} // Update the payment with the company transaction id and auth code $payment->trans_id = $ct->id; $payment->auth_code = $cc_processor->getAuthCode(); if($payment->update() === FALSE){ $error_msg .= "Error updating payment with company transaction id!\n"; debug_message($payment->getLastError()); } if(empty($error_msg)){ if(isset($_POST['email_invoice']) && $_POST['email_invoice'] == 'Y'){ $invoice = new SI_Invoice(); if($invoice->get(intval($_POST['invoice_id'])) === FALSE){ $error_msg .= "Error retreiving invoice!\n"; debug_message($invoice->getLastError()); } if($invoice->sendEmail('InvoiceEmail') === FALSE){ $error_msg .= "Error sending invoice notification!\n"; debug_message($invoice->getLastError()); } } if(empty($error_msg)){ goBack(); } } }else{ $error_msg .= "Error adding Payment!\n"; debug_message($payment->getLastError()); }
} // Create invoices $invoice = new SI_Invoice(); 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']));
print("Writing output to $output_directory\n"); if(($start_date > 0 && $end_date == 0) || ($end_date > 0 && $start_date == 0)){ print("You must provide both a start and an end date\n"); exit(2); } if($start_date > 0){ print("Looking up invoices between ".date('m/d/Y', $start_date)." and ".date('m/d/Y', $end_date).".\n"); } $invoice = new SI_Invoice(); $invoices = $invoice->retrieveSet("WHERE `timestamp` BETWEEN $start_date AND $end_date"); if($invoices === FALSE){ print("Error retreiving list of invoices!\n"); print($invoice->getLastError()."\n"); exit(3); } print("Exporting ".count($invoices)." invoices.\n"); foreach($invoices as $invoice){ if(!is_array($invoice->_lines) || count($invoice->_lines) == 0){ print("Skipping invoice {$invoice->id}.\n"); continue; } $pdf_file = $invoice->getPDF(FALSE); if($pdf_file === FALSE){ print("Error creating PDF invoice.\n"); print($invoice->getLastError()."\n"); exit(4);
$code = new SI_ItemCode(); $output = $code->exportQB(); if($output === FALSE){ fatal_error("Error getting item code export data!\n".$code->getLastError()); } }elseif(strtolower($_REQUEST['mode']) == 'account'){ $account = new SI_Account(); $output = $account->exportQB(); if($output === FALSE){ fatal_error("Error getting account export data!\n".$account->getLastError()); } }elseif(strtolower($_REQUEST['mode']) == 'payment'){ $payment = new SI_Payment(); $output = $payment->exportQB(); if($output === FALSE){ fatal_error("Error getting payment export data!\n".$payment->getLastError()); } }elseif(strtolower($_REQUEST['mode']) == 'invoice'){ $invoice = new SI_Invoice(); $output = $invoice->exportQB(); if($output === FALSE){ fatal_error("Error getting invoice export data!\n".$invoice->getLastError()); } }else{ fatal_error("Unknown export mode!"); } ob_end_clean(); header('Content-type: application/iif'); header('Content-Disposition: attachment; filename="'.$_REQUEST[mode].'.iif"'); print($output);
*/ require_once('includes/common.php'); require_once('includes/SI_Invoice.php'); require_once('includes/SI_Company.php'); require_once('includes/SI_PDFInvoice.php'); checkLogin('accounting'); if(intval($_REQUEST['id']) == 0){ fatal_error("You must provide an invoice id to email!"); } $invoice = new SI_Invoice(); if($invoice->get(intval($_REQUEST['id'])) === FALSE){ $error_msg .= "Error retreiving invoice information!\n"; debug_message($invoice->getLastError()); } if(!$loggedin_user->hasRight('admin') && !$loggedin_user->hasRight('admin')){ if($loggedin_user->company_id != $invoice->company_id){ fatal_error("You do not have rights to access this invoice!"); } } $notification = 'InvoiceEmail'; if(isset($_REQUEST['notification'])){ $notification = $_REQUEST['notification']; } if($invoice->sendEmail($notification) === FALSE) fatal_error("Error sending invoice:\n".$invoice->getLastError()); goBack(0);