After a rage with TRS, allowed `dispense acct` to take -ve, disabled new background...
[tpg/opendispense2.git] / src / server / dispense.c
index 3fb5652..23e73af 100644 (file)
@@ -105,6 +105,39 @@ int DispenseGive(int ActualUser, int SrcUser, int DestUser, int Ammount, const c
        return 0;
 }
 
+/**
+ * \brief Move money from one user to another (Admin Only)
+ */
+int DispenseTransfer(int ActualUser, int SrcUser, int DestUser, int Ammount, const char *ReasonGiven)
+{
+        int    ret;
+       char    *actualUsername;
+       char    *srcName, *dstName;
+
+       // Make sure the user is an admin
+       if( !(Bank_GetFlags(ActualUser) & USER_FLAG_ADMIN) )
+               return 1;
+       
+       ret = _Transfer( SrcUser, DestUser, Ammount, ReasonGiven );
+       if(ret) return 2;       // No Balance
+       
+       
+       actualUsername = Bank_GetAcctName(ActualUser);
+       srcName = Bank_GetAcctName(SrcUser);
+       dstName = Bank_GetAcctName(DestUser);
+       
+       Log_Info("move %i to %s from %s by %s [balances %i, %i] - %s",
+               Ammount, dstName, srcName, actualUsername,
+               Bank_GetBalance(SrcUser), Bank_GetBalance(DestUser),
+               ReasonGiven
+               );
+       
+       free(srcName);
+       free(dstName);
+       free(actualUsername);
+       
+       return 0;
+}
 /**
  * \brief Add money to an account
  */
@@ -113,7 +146,11 @@ int DispenseAdd(int ActualUser, int User, int Ammount, const char *ReasonGiven)
         int    ret;
        char    *dstName, *byName;
        
-       ret = _Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT), User, Ammount, ReasonGiven );
+#if DISPENSE_ADD_BELOW_MIN
+//     ret = _Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT), User, Ammount, ReasonGiven );
+#else
+       ret = Bank_Transfer( Bank_GetAcctByName(COKEBANK_DEBT_ACCT), User, Ammount, ReasonGiven );
+#endif
        if(ret) return 2;
        
        byName = Bank_GetAcctName(ActualUser);
@@ -196,11 +233,11 @@ int _GetMinBalance(int Account)
        // - Internal accounts have no lower bound
        if( flags & USER_FLAG_INTERNAL )        return INT_MIN;
        
-       // Admin to -$10
-       //if( flags & USER_FLAG_ADMIN ) return -1000;
+       // Admin to -$50
+       if( flags & USER_FLAG_ADMIN )   return -5000;
        
-       // Coke to -$5
-       //if( flags & USER_FLAG_COKE )  return -500;
+       // Coke to -$20
+       if( flags & USER_FLAG_COKE )    return -2000;
        
        // Anyone else, non-negative
        return 0;
@@ -213,12 +250,12 @@ int _CanTransfer(int Source, int Destination, int Ammount)
 {
        if( Ammount > 0 )
        {
-               if( Bank_GetBalance(Source) + Ammount < _GetMinBalance(Source) )
+               if( Bank_GetBalance(Source) - Ammount < _GetMinBalance(Source) )
                        return 0;
        }
        else
        {
-               if( Bank_GetBalance(Destination) - Ammount < _GetMinBalance(Destination) )
+               if( Bank_GetBalance(Destination) + Ammount < _GetMinBalance(Destination) )
                        return 0;
        }
        return 1;

UCC git Repository :: git.ucc.asn.au