// Create checks $check = new SI_Check(); foreach ($checks as $number => $data) { if ($number == 0) { continue; } // debug("Going to create check $number for amount ".$data['amount']." with ids ".join(', ', $data['ids'])); $check->user_id = $data['user_id']; $check->number = $number; $check->timestamp = $data['timestamp']; $check->amount = $data['amount']; $check->type = 'CHECK'; $check->name = $users[$data['user_id']]['first_name'] . ' ' . $users[$data['user_id']]['last_name']; $check->address1 = $users[$data['user_id']]['address1']; $check->address2 = $users[$data['user_id']]['address2']; $check->city = $users[$data['user_id']]['city']; $check->state = $users[$data['user_id']]['state']; $check->zip = $users[$data['user_id']]['zip']; assert_die($check->add(), "Error adding check: " . $check->getLastError()); assert_die($check->attachCostTransactions($data['ids']), "Error adding cost transactions to check: " . $check->getLastError()); // Add user transaction $ut = new SI_UserTransaction(); $ut->amount = -$check->amount; $ut->description = "Check #" . $check->number; $ut->timestamp = $check->timestamp; $ut->user_id = $check->user_id; assert_die($ut->add(), "Error adding user transaction: " . $ut->getLastError()); // Update check trans id $check->trans_id = $ut->id; assert_die($check->update(), "Error updating transaction id for check: " . $check->getLastError()); }
if($check->type == 'CHECK'){ $desc = "Check #".$check->number; }elseif($check->type == "EFT"){ $desc = "Electronic Funds Transfer"; } $ut = new SI_UserTransaction(); $ut->amount = -$total_amount; $ut->description = $desc; $ut->timestamp = $check->timestamp; $ut->user_id = $user->id; if($ut->add() === FALSE){ $error_msg .= "Error adding user transaction"; debug_message($ut->getLastError()); }else{ $check->trans_id = $ut->id; if($check->update() === FALSE){ $error_msg .= "Error updating transaction id for check"; debug_message($check->getLastError()); } } if(empty($error_msg)){ goBack(); } }else{ $error_msg .= "Error adding Check!\n"; debug_message($check->getLastError()); } } }