include $_SERVER['DOCUMENT_ROOT'] . "/WebBuilder/WebApp.class.php";
$db = new DBMain();
// BUILD quote Contents
$content = '';
$index = 1;
while ($index < $_POST['rows']) {
if (strlen($_POST['item_desciption_' . $index]) < 1) {
// echo 'les than' . strlen($_POST['item_desciption_' . $index]) . " : {$_POST['item_desciption_' .$index]}";
// echo "
$index
";
} else {
$content = $content . $_POST['item_desciption_' . $index] . "," . $_POST['item_quantity_' . $index] . "," . $_POST['item_amount_' . $index] . "," . $_POST['item_discount_' . $index] . "," . $_POST['item_total_' . $index] . ";";
}
$index++;
}
// echo $content;
// echo "
";
$record_id = $db->Update('quotes', ['quote_no', 'quote_content', 'total', 'clients_id', 'status', 'date_created', 'date_sent', 'date_exp', 'description'], [$_POST['quote_no'], $content, $_POST['total'], $_POST['client_id'], $_POST['status'], $_POST['date'], '', $_POST['exp_date'], $_POST['description']], "record_id = {$_POST['record_id']}");
if (isset($_POST['cvt_invoice'])) {
echo "CONVERTING...";
$invoice_res_no = $db->exec_query('invoices', ['*'], '', '', '', '', '1', "ORDER BY record_id DESC");
$invoice_info_no = $invoice_res_no->fetch_assoc();
$invoice_no = $invoice_info_no['invoice_no'] + 1;
$invoice_id = $db->insert("INSERT INTO invoices (
`invoice_no`,
`invoices_name`,
`invoice_content`,
`quotes_id`,
`total`,
`clients_id`,
`status`,
`date_created`,
`date_sent`,
`date_due`,
`description`
) values (
$invoice_no,
'$invoice_no',
'$content',
$record_id,
{$_POST['total']},
{$_POST['client_id']},
'{$_POST['status']}',
'{$_POST['date']}',
'',
'{$_POST['exp_date']}',
'{$_POST['description']}'
)");
echo "";
}
if ($record_id > 0) {
echo "";
} else {
echo "ENCOUNTERED AN ERROR PLEASE TRY AGAIN";
}