* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ // if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language // if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language // if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); // if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); if (!defined('NOCSRFCHECK')) { define('NOCSRFCHECK', '1'); } if (!defined('NOTOKENRENEWAL')) { define('NOTOKENRENEWAL', '1'); } if (!defined('NOREQUIREMENU')) { define('NOREQUIREMENU', '1'); } if (!defined('NOREQUIREHTML')) { define('NOREQUIREHTML', '1'); } if (!defined('NOREQUIREAJAX')) { define('NOREQUIREAJAX', '1'); } require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; $langs->loadLangs(array("bills", "cashdesk")); $id = GETPOST('id', 'int'); $action = GETPOST('action', 'alpha'); $idproduct = GETPOST('idproduct', 'int'); $place = (GETPOSTISSET('place')?GETPOST('place', 'int'):0); // $place is id of POS $number = GETPOST('number'); $idline = GETPOST('idline'); $desc = GETPOST('desc', 'alpha'); $pay = GETPOST('pay'); $placeid = 0; // $placeid is id of invoice $invoice = new Facture($db); $ret = $invoice->fetch('', '(PROV-POS-'.$place.')'); if ($ret > 0) $placeid = $invoice->id; /* * Actions */ if ($action == 'valid' && $user->rights->facture->creer) { if ($pay == "cash") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CASH; elseif ($pay == "card") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CB; elseif ($pay == "cheque") $bankaccount = $conf->global->CASHDESK_ID_BANKACCOUNT_CHEQUE; $now=dol_now(); $invoice = new Facture($db); $invoice->fetch($placeid); if (! empty($conf->stock->enabled) and $conf->global->CASHDESK_NO_DECREASE_STOCK!="1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE); else $invoice->validate($user); // Add the payment $payment=new Paiement($db); $payment->datepaye = $now; $payment->bank_account = $bankaccount; $payment->amounts[$invoice->id] = $invoice->total_ttc; if ($pay=="cash") $payment->paiementid = 4; elseif ($pay=="card") $payment->paiementid = 6; elseif ($pay=="cheque") $payment->paiementid = 7; $payment->num_payment = $invoice->ref; $payment->create($user); $payment->addPaymentToBank($user, 'payment', '(CustomerInvoicePayment)', $bankaccount, '', ''); $invoice->set_paid($user); } if (($action=="addline" || $action=="freezone") && $placeid == 0) { $invoice->socid = $conf->global->CASHDESK_ID_THIRDPARTY; $invoice->date = dol_now(); $invoice->ref = "(PROV-POS-".$place.")"; $invoice->module_source = 'takepos'; $invoice->pos_source = (string) $place; $placeid = $invoice->create($user); } if ($action == "addline") { $prod = new Product($db); $prod->fetch($idproduct); $price = $prod->price; $tva_tx = $prod->tva_tx; $price_ttc = $prod->price_ttc; $price_base_type = $prod->price_base_type; if (! empty($conf->global->PRODUIT_MULTIPRICES)) { $customer = new Societe($db); $customer->fetch($invoice->socid); $price = $prod->multiprices[$customer->price_level]; $tva_tx = $prod->multiprices_tva_tx[$customer->price_level]; $price_ttc = $prod->multiprices_ttc[$customer->price_level]; $price_base_type = $prod->multiprices_base_type[$customer->price_level]; } $invoice->addline($prod->description, $price, 1, $tva_tx, $prod->localtax1_tx, $prod->localtax2_tx, $idproduct, $prod->remise_percent, '', 0, 0, 0, '', $price_base_type, $price_ttc, $prod->type, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); $invoice->fetch($placeid); } if ($action == "freezone") { $invoice->addline($desc, $number, 1, $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS, 0, 0, 0, 0, '', 0, 0, 0, '', 'TTC', $number, 0, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', null, 0); $invoice->fetch($placeid); } if ($action == "addnote") { foreach($invoice->lines as $line) { if ($line->id == $number) { $line->array_options['order_notes'] = $desc; $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } $invoice->fetch($placeid); } if ($action == "deleteline") { if ($idline > 0 and $placeid > 0) { //If exist invoice and line, to avoid errors if deleted from other device or no line selected $invoice->deleteline($idline); $invoice->fetch($placeid); } elseif ($placeid > 0) { //If exist invoice, but no line selected, proced to delete last line $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "facturedet where fk_facture='$placeid' order by rowid DESC"; $resql = $db->query($sql); $row = $db->fetch_array($resql); $deletelineid = $row[0]; $invoice->deleteline($deletelineid); $invoice->fetch($placeid); } } if ($action == "updateqty") { foreach($invoice->lines as $line) { if ($line->id == $idline) { $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $number, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } $invoice->fetch($placeid); } if ($action == "updateprice") { foreach($invoice->lines as $line) { if ($line->id == $idline) { $result = $invoice->updateline($line->id, $line->desc, $number, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } $invoice->fetch($placeid); } if ($action == "updatereduction") { foreach($invoice->lines as $line) { if ($line->id == $idline) { $result = $invoice->updateline($line->id, $line->desc, $line->subprice, $line->qty, $number, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); } } $invoice->fetch($placeid); } if ($action == "order" and $placeid != 0) { include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $headerorder = '
' . $langs->trans('Place') . ' ' . $place . '
'; $footerorder = '
' . $langs->trans("Label") . '' . $langs->trans("Qty") . '
' . dol_print_date(dol_now(), 'dayhour') . '
'; $order_receipt_printer1 = ""; $order_receipt_printer2 = ""; $catsprinter1 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_1); $catsprinter2 = explode(';', $conf->global->TAKEPOS_PRINTED_CATEGORIES_2); foreach($invoice->lines as $line) { if ($line->special_code == "3") { continue; } $c = new Categorie($db); $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); $result = array_intersect($catsprinter1, $existing); $count = count($result); if ($count > 0) { $sql = "UPDATE " . MAIN_DB_PREFIX . "facturedet set special_code='3' where rowid=$line->rowid"; $db->query($sql); $order_receipt_printer1.= '' . $line->product_label . '' . $line->qty; if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer1.="
(".$line->array_options['options_order_notes'].")"; $order_receipt_printer1.=''; } } foreach($invoice->lines as $line) { if ($line->special_code == "3") { continue; } $c = new Categorie($db); $existing = $c->containing($line->fk_product, Categorie::TYPE_PRODUCT, 'id'); $result = array_intersect($catsprinter2, $existing); $count = count($result); if ($count > 0) { $sql = "UPDATE " . MAIN_DB_PREFIX . "facturedet set special_code='3' where rowid=$line->rowid"; $db->query($sql); $order_receipt_printer2.= '' . $line->product_label . '' . $line->qty; if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer2.="
(".$line->array_options['options_order_notes'].")"; $order_receipt_printer2.=''; } } $invoice->fetch($placeid); } ?> '; print ''; print ''; print ''; print ''; print ''; print "\n"; if ($placeid > 0) { foreach($invoice->lines as $line) { print ''; print ''; print ''; print ''; print ''; } } print '
' . $langs->trans('Description') . '' . $langs->trans('Qty') . '' . $langs->trans('TotalHTShort') . '
' . $line->product_label . $line->desc; if (!empty($line->array_options['options_order_notes'])) echo "
(".$line->array_options['options_order_notes'].")"; print '
' . $line->qty . '' . price($line->total_ttc) . '
'; print '

'.$langs->trans('TotalTTC'); if($conf->global->TAKEPOS_BAR_RESTAURANT) print " ".$langs->trans('Place')." ".$place; print ': '.price($invoice->total_ttc, 1, '', 1, - 1, - 1, $conf->currency).' 

'; if ($invoice->socid != $conf->global->CASHDESK_ID_THIRDPARTY) { $soc = new Societe($db); if ($invoice->socid > 0) $soc->fetch($invoice->socid); else $soc->fetch($conf->global->CASHDESK_ID_THIRDPARTY); print '

'; print $langs->trans("Customer").': '.$soc->name; print '

'; } if ($action=="valid") { print '

'.$invoice->ref." ".$langs->trans('BillShortStatusValidated').'

'; if ($conf->global->TAKEPOSCONNECTOR) print '
'; else print '
'; } if ($action == "search") { print '
'; } print '';