$q = "SELECT * FROM " . PRFX . "CONFIG_WORK_ORDER_STATUS WHERE CONFIG_WORK_ORDER_STATUS_ID=" . $db->qstr($stats['WORK_ORDER_STATUS']); if (!($rs = $db->Execute($q))) { force_page('core', 'error&error_msg=MySQL Error: ' . $db->ErrorMsg() . '&menu=1&type=database'); exit; } $stats2 = $rs->FetchRow(); // Labour Section /* get any labour database rows */ $q = "SELECT * FROM " . PRFX . "TABLE_INVOICE_LABOR WHERE INVOICE_ID=" . $db->qstr($invoice['INVOICE_ID']); if (!($rs = $db->execute($q))) { force_page('core', 'error&error_msg=MySQL Error: ' . $db->ErrorMsg() . '&menu=1'); exit; } $labor = $rs->GetArray(); /* Sum Labour Sub Totals */ $labour_sub_total_sum = labour_sub_total_sum($db, $invoice_id); //Labour Lookup for PDF - uses a mysql query rather than an arrray $query = mysql_query('select INVOICE_LABOR_UNIT, INVOICE_LABOR_DESCRIPTION, INVOICE_LABOR_RATE, INVOICE_LABOR_SUBTOTAL from ' . PRFX . 'TABLE_INVOICE_LABOR WHERE INVOICE_ID=' . $db->qstr($invoice['INVOICE_ID'])); $labour_row_pdf = $query or die(mysql_error() . '<br />' . $query); // Parts Section /* get any parts database rows */ $q = "SELECT * FROM " . PRFX . "TABLE_INVOICE_PARTS WHERE INVOICE_ID=" . $db->qstr($invoice['INVOICE_ID']); if (!($rs = $db->execute($q))) { force_page('core', 'error&error_msg=MySQL Error: ' . $db->ErrorMsg() . '&menu=1'); exit; } $parts = $rs->GetArray(); /* Sum Parts Sub Total */ $parts_sub_total_sum = parts_sub_total_sum($db, $invoice_id); //Parts Lookup for PDF - uses a mysql query rather than an arrray // mysql_select_db( $DB_NAME , $link );
$trans = $rs->GetArray(); $smarty->assign('trans', $trans); } /* load labor rate into array */ $q = "SELECT * FROM " . PRFX . "TABLE_LABOR_RATE WHERE LABOR_RATE_ACTIVE='1'"; $rs = $db->execute($q); $rate = $rs->GetArray(); $smarty->assign('rate', $rate); /* Assign company information */ $q = "SELECT * FROM " . PRFX . "TABLE_COMPANY"; $rs = $db->Execute($q); $company = $rs->GetArray(); $smarty->assign('company', $company); $smarty->assign('invoice', $invoice); // Sub_total results $labour_sub_total_sum = labour_sub_total_sum($db, $invoice['INVOICE_ID']); $parts_sub_total_sum = parts_sub_total_sum($db, $invoice['INVOICE_ID']); $smarty->assign('labour_sub_total_sum', $labour_sub_total_sum); $smarty->assign('parts_sub_total_sum', $parts_sub_total_sum); $smarty->display('invoice' . SEP . 'new.tpl'); // If discount is greate than 100% then these close WO and mark the invoice as paid if ($VAR['discount'] >= 100) { $q = "UPDATE " . PRFX . "TABLE_WORK_ORDER SET\n WORK_ORDER_STATUS\t\t= '6',\n WORK_ORDER_CURRENT_STATUS \t= '8'\n WHERE WORK_ORDER_ID \t\t=" . $db->qstr($wo_id); if (!($rs = $db->execute($q))) { force_page('core', 'error&error_msg=MySQL Error: ' . $db->ErrorMsg() . '&menu=1'); exit; } } if ($VAR['discount'] >= 100) { /* update the invoice */ $q = "UPDATE " . PRFX . "TABLE_INVOICE SET\n PAID_DATE \t\t= " . $db->qstr(time()) . ",\n PAID_AMOUNT \t\t= '0',\n INVOICE_PAID\t\t= '1'\n WHERE INVOICE_ID \t= " . $db->qstr($VAR['invoice_id']);
if (empty($labor)) { $smarty->assign('labor', 0); } else { $smarty->assign('labor', $labor); } /* get any parts */ $q = 'SELECT * FROM ' . PRFX . 'TABLE_INVOICE_PARTS WHERE INVOICE_ID=' . $db->qstr($invoice['INVOICE_ID']); if (!($rs = $db->execute($q))) { force_page('core', 'error&error_msg=MySQL Error: ' . $db->ErrorMsg() . '&menu=1'); exit; } $parts = $rs->GetArray(); if (empty($parts)) { $smarty->assign('parts', 0); } else { $smarty->assign('parts', $parts); } /* Get transaction information */ $q = 'SELECT * FROM ' . PRFX . 'TABLE_TRANSACTION WHERE INVOICE_ID =' . $db->qstr($invoice['INVOICE_ID']); if (!($rs = $db->execute($q))) { force_page('core', 'error&error_msg=MySQL Error: ' . $db->ErrorMsg() . '&menu=1'); exit; } $trans = $rs->GetArray(); $smarty->assign('trans', $trans); // Sub_total results $labour_sub_total_sum = labour_sub_total_sum($db, $VAR['invoice_id']); $parts_sub_total_sum = parts_sub_total_sum($db, $VAR['invoice_id']); $smarty->assign('labour_sub_total_sum', $labour_sub_total_sum); $smarty->assign('parts_sub_total_sum', $parts_sub_total_sum); $smarty->display('invoice' . SEP . 'view.tpl');