foreach ($invoices as $number => $data) { if ($number == 0) { continue; } // debug("Going to create invoice $number for company id ".$data['company_id']." with ids ".join(', ', $data['ids'])); $company =& $companies[$data['company_id']]; $invoice_insert_sql = "\nINSERT INTO invoices (id, company_id, address1, address2, city, \nstate, zip, timestamp, terms, trans_id)\nVALUES(" . $number . ", " . $data['company_id'] . ", '" . $company['address1'] . "', '" . $company['address2'] . "', '" . $company['city'] . "', \n'" . $company['state'] . "', '" . $company['zip'] . "', " . $data['timestamp'] . ", 'NET15', 0)\n\t"; $invoice_result = $si_db->query($invoice_insert_sql, TRUE); assert_die($invoice_result, "Could not add invoice!\n" . $si_db->getLastError()); // Add activities $invoice->get($number); // debug("Adding line items to invoice ".$invoice->id); assert_die($invoice->addTaskActivities($data['ids']), "Error adding task activities to invoice: " . $invoice->getLastError()); // Add the company transaction $ct = new SI_CompanyTransaction(); $ct->amount = $invoice->getTotal(); $ct->company_id = $invoice->company_id; $ct->description = "Invoice #" . $invoice->id; $ct->timestamp = $invoice->timestamp; assert_die($ct->add(), "Error adding company transaction: " . $ct->getLastError()); } // 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'];
if($company->get($company_id) === FALSE){ fatal_error("Could not get company for id $company_id"); } $invoice = new SI_Invoice(); if($invoice->get($_REQUEST['invoice_id']) === FALSE){ fatal_error("Could not get invoice {$_REQUEST['invoice_id']}\n"); } $payment = new SI_Payment(); $payment->company_id = $company_id; $title = "Add Payment"; if($_POST['save']){ $payment->amount = preg_replace('/[^0-9\.]/','', $_POST['amount']); if($payment->amount > $invoice->getTotal()){ fatal_error("Amount can not be more than amount due on the invoice!\n"); } $payment->timestamp = time(); $payment->type = 'CC'; // Process the card $cc_processor = SI_CCProcessor::getInstance(); $params = array( 'id' => $company_id, 'first_name' => $_POST['card_first_name'], 'last_name' => $_POST['card_last_name'], 'address' => $_POST['card_address'], 'city' => $_POST['card_city'], 'state' => $_POST['card_state'], 'zip' => $_POST['card_zip'],
</td> </tr> <? } ?> <? } // end for links if($i != count($activities)-1){?> <tr> <td colspan="11" class="dg_header_cell"> </td> </tr> <? } //If not last ?> <? } //If detail ?> <? }?> </tbody> <tr> <td colspan="5" class="form_header_cell" align="right">Total:</td> <td class="form_field_cell"><?php echo SureInvoice::getCurrencySymbol() . number_format($invoice->getTotal(), 2); ?> </td> </tr> </table> </div> </div> <? if(count($payments) > 0){ ?> <div class="tableContainer"> <a href="javascript:;" class="tCollapse" onclick="toggleGrid(this)"><img src="images/arrow_down.jpg" alt="Hide table" />Payments</a><div> <table border="0" cellspacing="0" cellpadding="0" class="dg_table"> <tr> <th class="dg_header_cell"><a class="link1" href="" onclick="return sortTable('bodyId', 0, 1, false)">Date</a></th> <th class="dg_header_cell"><a class="link1" href="" onclick="return sortTable('bodyId', 1, 0, false)">Type</a></th> <th class="dg_header_cell"><a class="link1" href="" onclick="return sortTable('bodyId', 2, 0, false)">Amount</a></th> </tr>