2018-09-28 13:31:41 +02:00
< ? php
2018-12-07 17:02:06 +01:00
/**
* Copyright ( C ) 2018 Andreu Bisquerra < jove @ bisquerra . com >
2018-09-28 13:31:41 +02:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2018-09-28 13:31:41 +02:00
*/
2019-03-28 09:56:01 +01:00
/**
* \file htdocs / takepos / invoice . php
* \ingroup takepos
* \brief Page to generate section with list of lines
*/
2019-03-15 12:07:33 +01:00
// 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');
2019-11-12 00:15:34 +01:00
if ( ! defined ( 'NOCSRFCHECK' )) { define ( 'NOCSRFCHECK' , '1' ); }
2018-12-15 16:10:44 +01:00
if ( ! defined ( 'NOTOKENRENEWAL' )) { define ( 'NOTOKENRENEWAL' , '1' ); }
2019-11-12 00:15:34 +01:00
if ( ! defined ( 'NOREQUIREMENU' )) { define ( 'NOREQUIREMENU' , '1' ); }
if ( ! defined ( 'NOREQUIREHTML' )) { define ( 'NOREQUIREHTML' , '1' ); }
if ( ! defined ( 'NOREQUIREAJAX' )) { define ( 'NOREQUIREAJAX' , '1' ); }
2018-12-07 08:04:40 +01:00
2019-03-14 16:35:36 +01:00
require '../main.inc.php' ;
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2018-12-07 08:04:40 +01:00
2019-09-03 14:48:46 +02:00
$langs -> loadLangs ( array ( " companies " , " commercial " , " bills " , " cashdesk " , " stocks " ));
2019-03-14 16:35:36 +01:00
2018-12-07 08:04:40 +01:00
$id = GETPOST ( 'id' , 'int' );
$action = GETPOST ( 'action' , 'alpha' );
$idproduct = GETPOST ( 'idproduct' , 'int' );
2019-11-12 00:15:34 +01:00
$place = ( GETPOST ( 'place' , 'int' ) > 0 ? GETPOST ( 'place' , 'int' ) : 0 ); // $place is id of table for Bar or Restaurant
2020-01-01 21:54:47 +01:00
$placeid = 0 ; // $placeid is ID of invoice
2019-03-27 20:13:12 +01:00
2019-11-12 00:15:34 +01:00
if ( $conf -> global -> TAKEPOS_PHONE_BASIC_LAYOUT == 1 && $conf -> browser -> layout == 'phone' )
2019-05-26 16:44:17 +02:00
{
// DIRECT LINK TO THIS PAGE FROM MOBILE AND NO TERMINAL SELECTED
2019-11-12 00:15:34 +01:00
if ( $_SESSION [ " takeposterminal " ] == " " )
2019-05-26 16:44:17 +02:00
{
2019-11-12 00:15:34 +01:00
if ( $conf -> global -> TAKEPOS_NUM_TERMINALS == " 1 " ) $_SESSION [ " takeposterminal " ] = 1 ;
2019-05-26 16:44:17 +02:00
else
{
header ( " Location: takepos.php " );
exit ;
}
}
$mobilepage = GETPOST ( 'mobilepage' , 'alpha' );
2019-11-12 00:15:34 +01:00
$title = 'TakePOS - Dolibarr ' . DOL_VERSION ;
if ( ! empty ( $conf -> global -> MAIN_APPLICATION_TITLE )) $title = 'TakePOS - ' . $conf -> global -> MAIN_APPLICATION_TITLE ;
$head = ' < meta name = " apple-mobile-web-app-title " content = " TakePOS " />
2019-05-26 16:44:17 +02:00
< meta name = " apple-mobile-web-app-capable " content = " yes " >
< meta name = " mobile-web-app-capable " content = " yes " >
< meta name = " viewport " content = " width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no " /> ' ;
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss );
print ' < link rel = " stylesheet " href = " css/pos.css " >
< link rel = " stylesheet " href = " css/colorbox.css " type = " text/css " media = " screen " />
< script type = " text/javascript " src = " js/jquery.colorbox-min.js " ></ script > ' ;
}
2019-03-22 09:06:44 +01:00
/**
* Abort invoice creationg with a given error message
*
* @ param string $message Message explaining the error to the user
* @ return void
*/
function fail ( $message )
{
2019-11-12 00:15:34 +01:00
header ( $_SERVER [ 'SERVER_PROTOCOL' ] . ' 500 Internal Server Error' , true , 500 );
2019-03-22 09:06:44 +01:00
die ( $message );
}
2019-03-27 12:40:32 +01:00
$number = GETPOST ( 'number' , 'alpha' );
$idline = GETPOST ( 'idline' , 'int' );
2018-12-07 08:04:40 +01:00
$desc = GETPOST ( 'desc' , 'alpha' );
2019-03-27 12:40:32 +01:00
$pay = GETPOST ( 'pay' , 'alpha' );
$amountofpayment = price2num ( GETPOST ( 'amount' , 'alpha' ));
2018-12-07 08:04:40 +01:00
2019-03-27 15:42:53 +01:00
$invoiceid = GETPOST ( 'invoiceid' , 'int' );
2019-03-14 16:35:36 +01:00
2019-03-26 20:01:06 +01:00
$paycode = $pay ;
2019-11-12 00:15:34 +01:00
if ( $pay == 'cash' ) $paycode = 'LIQ' ; // For backward compatibility
if ( $pay == 'card' ) $paycode = 'CB' ; // For backward compatibility
if ( $pay == 'cheque' ) $paycode = 'CHQ' ; // For backward compatibility
2019-03-27 12:40:32 +01:00
2019-03-15 12:07:33 +01:00
// Retrieve paiementid
2019-03-25 16:49:33 +01:00
$sql = " SELECT id FROM " . MAIN_DB_PREFIX . " c_paiement " ;
2019-11-12 00:15:34 +01:00
$sql .= " WHERE entity IN ( " . getEntity ( 'c_paiement' ) . " ) " ;
$sql .= " AND code = ' " . $db -> escape ( $paycode ) . " ' " ;
2019-03-15 12:07:33 +01:00
$resql = $db -> query ( $sql );
$codes = $db -> fetch_array ( $resql );
2019-11-12 00:15:34 +01:00
$paiementid = $codes [ 0 ];
2019-03-15 12:07:33 +01:00
2019-03-27 12:40:32 +01:00
2019-03-27 15:42:53 +01:00
$invoice = new Facture ( $db );
if ( $invoiceid > 0 )
{
$ret = $invoice -> fetch ( $invoiceid );
}
else
{
2019-05-14 19:58:08 +02:00
$ret = $invoice -> fetch ( '' , '(PROV-POS' . $_SESSION [ " takeposterminal " ] . '-' . $place . ')' );
2019-03-27 15:42:53 +01:00
}
if ( $ret > 0 )
{
$placeid = $invoice -> id ;
}
2020-01-01 21:54:47 +01:00
$constforcompanyid = 'CASHDESK_ID_THIRDPARTY' . $_SESSION [ " takeposterminal " ];
$soc = new Societe ( $db );
if ( $invoice -> socid > 0 ) $soc -> fetch ( $invoice -> socid );
else $soc -> fetch ( $conf -> global -> $constforcompanyid );
2019-03-27 15:42:53 +01:00
2018-09-28 13:31:41 +02:00
/*
2019-03-26 20:01:06 +01:00
* Actions
*/
2018-09-28 13:31:41 +02:00
2018-12-15 16:08:58 +01:00
if ( $action == 'valid' && $user -> rights -> facture -> creer )
{
2019-05-14 19:58:08 +02:00
if ( $pay == " cash " ) $bankaccount = $conf -> global -> { 'CASHDESK_ID_BANKACCOUNT_CASH' . $_SESSION [ " takeposterminal " ]}; // For backward compatibility
elseif ( $pay == " card " ) $bankaccount = $conf -> global -> { 'CASHDESK_ID_BANKACCOUNT_CB' . $_SESSION [ " takeposterminal " ]}; // For backward compatibility
elseif ( $pay == " cheque " ) $bankaccount = $conf -> global -> { 'CASHDESK_ID_BANKACCOUNT_CHEQUE' . $_SESSION [ " takeposterminal " ]}; // For backward compatibility
2019-03-27 12:40:32 +01:00
else
2019-03-26 20:02:18 +01:00
{
2019-11-12 00:15:34 +01:00
$accountname = " CASHDESK_ID_BANKACCOUNT_ " . $pay . $_SESSION [ " takeposterminal " ];
$bankaccount = $conf -> global -> $accountname ;
2019-03-26 20:02:18 +01:00
}
2019-11-12 00:15:34 +01:00
$now = dol_now ();
2019-09-24 14:25:02 +02:00
$res = 0 ;
2019-03-14 16:35:36 +01:00
2018-09-28 13:31:41 +02:00
$invoice = new Facture ( $db );
$invoice -> fetch ( $placeid );
2019-10-17 12:28:48 +02:00
if ( $invoice -> total_ttc < 0 ) {
2019-11-12 00:15:34 +01:00
$invoice -> type = $invoice :: TYPE_CREDIT_NOTE ;
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " facture WHERE " ;
$sql .= " fk_soc = ' " . $invoice -> socid . " ' " ;
$sql .= " AND type <> " . Facture :: TYPE_CREDIT_NOTE . " " ;
$sql .= " AND fk_statut >= " . $invoice :: STATUS_VALIDATED . " " ;
$sql .= " ORDER BY rowid DESC " ;
2019-03-22 09:06:44 +01:00
$resql = $db -> query ( $sql );
2019-11-12 00:15:34 +01:00
if ( $resql ) {
2019-03-22 09:06:44 +01:00
$obj = $db -> fetch_object ( $resql );
2019-11-12 00:15:34 +01:00
$fk_source = $obj -> rowid ;
if ( $fk_source == null ) {
2019-03-22 09:06:44 +01:00
fail ( $langs -> transnoentitiesnoconv ( " NoPreviousBillForCustomer " ));
}
2019-11-12 00:15:34 +01:00
} else {
2019-03-22 09:06:44 +01:00
fail ( $langs -> transnoentitiesnoconv ( " NoPreviousBillForCustomer " ));
}
2019-11-12 00:15:34 +01:00
$invoice -> fk_facture_source = $fk_source ;
2019-03-22 09:06:44 +01:00
$invoice -> update ( $user );
}
2019-03-14 16:35:36 +01:00
2019-08-27 15:53:03 +02:00
$constantforkey = 'CASHDESK_NO_DECREASE_STOCK' . $_SESSION [ " takeposterminal " ];
2019-08-24 16:44:06 +02:00
if ( $invoice -> statut != Facture :: STATUS_DRAFT )
2019-03-27 15:42:53 +01:00
{
2019-10-20 22:01:54 +02:00
//If invoice is validated but it is not fully paid is not error and make the payment
2019-11-12 00:15:34 +01:00
if ( $invoice -> getRemainToPay () > 0 ) $res = 1 ;
else {
2019-10-20 22:01:54 +02:00
dol_syslog ( " Sale already validated " );
dol_htmloutput_errors ( $langs -> trans ( " InvoiceIsAlreadyValidated " , " TakePos " ), null , 1 );
}
2019-03-27 15:42:53 +01:00
}
2019-11-12 00:15:34 +01:00
elseif ( count ( $invoice -> lines ) == 0 )
2019-03-27 15:42:53 +01:00
{
2019-08-24 16:44:06 +02:00
dol_syslog ( " Sale without lines " );
dol_htmloutput_errors ( $langs -> trans ( " NoLinesToBill " , " TakePos " ), null , 1 );
2019-03-27 15:42:53 +01:00
}
2019-11-12 00:15:34 +01:00
elseif ( ! empty ( $conf -> stock -> enabled ) && $conf -> global -> $constantforkey != " 1 " )
2019-03-27 15:42:53 +01:00
{
2019-08-27 17:42:25 +02:00
$savconst = $conf -> global -> STOCK_CALCULATE_ON_BILL ;
2019-11-12 00:15:34 +01:00
$conf -> global -> STOCK_CALCULATE_ON_BILL = 1 ;
2019-03-14 16:35:36 +01:00
2019-08-27 15:39:35 +02:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
2019-08-27 17:42:25 +02:00
dol_syslog ( " Validate invoice with stock change into warehouse defined into constant " . $constantforkey . " = " . $conf -> global -> $constantforkey );
2019-09-24 10:08:48 +02:00
$res = $invoice -> validate ( $user , '' , $conf -> global -> $constantforkey );
2019-02-18 19:14:25 +01:00
2019-08-27 17:42:25 +02:00
$conf -> global -> STOCK_CALCULATE_ON_BILL = $savconst ;
2019-03-27 20:28:02 +01:00
}
else
{
2019-09-24 10:08:48 +02:00
$res = $invoice -> validate ( $user );
2019-03-27 12:40:32 +01:00
}
2019-03-14 16:35:36 +01:00
2019-10-17 12:28:48 +02:00
$remaintopay = $invoice -> getRemainToPay ();
2018-09-28 13:31:41 +02:00
// Add the payment
2019-10-17 12:28:48 +02:00
if ( $res >= 0 && $remaintopay > 0 ) {
2019-09-24 10:08:48 +02:00
$payment = new Paiement ( $db );
$payment -> datepaye = $now ;
$payment -> fk_account = $bankaccount ;
$payment -> amounts [ $invoice -> id ] = $amountofpayment ;
2019-09-24 14:25:02 +02:00
// If user has not used change control, add total invoice payment
2019-10-22 12:44:19 +02:00
if ( $amountofpayment == 0 ) $payment -> amounts [ $invoice -> id ] = $remaintopay ;
2019-09-24 14:25:02 +02:00
2019-11-12 00:15:34 +01:00
$payment -> paiementid = $paiementid ;
$payment -> num_payment = $invoice -> ref ;
2019-09-24 10:08:48 +02:00
$payment -> create ( $user );
$payment -> addPaymentToBank ( $user , 'payment' , '(CustomerInvoicePayment)' , $bankaccount , '' , '' );
2019-11-12 00:15:34 +01:00
$remaintopay = $invoice -> getRemainToPay (); // Recalculate remain to pay after the payment is recorded
2019-09-24 10:08:48 +02:00
if ( $remaintopay == 0 ) {
2019-10-17 12:28:48 +02:00
dol_syslog ( " Invoice is paid, so we set it to status Paid " );
2019-09-24 10:08:48 +02:00
$result = $invoice -> set_paid ( $user );
if ( $result > 0 ) $invoice -> paye = 1 ;
} else {
2019-11-12 00:15:34 +01:00
dol_syslog ( " Invoice is not paid, remain to pay = " . $remaintopay );
2019-09-24 10:08:48 +02:00
}
} else {
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
}
2018-09-28 13:31:41 +02:00
}
2019-04-28 18:12:33 +02:00
if ( $action == 'history' )
{
2019-11-28 23:31:28 +01:00
$placeid = ( int ) GETPOST ( 'placeid' , 'int' );
2019-04-28 18:12:33 +02:00
$invoice = new Facture ( $db );
$invoice -> fetch ( $placeid );
}
2019-11-12 00:15:34 +01:00
if (( $action == " addline " || $action == " freezone " ) && $placeid == 0 )
2018-09-28 13:31:41 +02:00
{
2020-01-01 21:54:47 +01:00
$invoice -> socid = $conf -> global -> $constforcompanyid ;
2019-03-14 16:35:36 +01:00
$invoice -> date = dol_now ();
$invoice -> module_source = 'takepos' ;
2019-05-14 19:58:08 +02:00
$invoice -> pos_source = $_SESSION [ " takeposterminal " ];
2019-03-14 16:35:36 +01:00
2019-08-01 12:23:02 +02:00
if ( $invoice -> socid <= 0 )
{
$langs -> load ( 'errors' );
dol_htmloutput_errors ( $langs -> trans ( " ErrorModuleSetupNotComplete " , " TakePos " ), null , 1 );
}
else
{
$placeid = $invoice -> create ( $user );
if ( $placeid < 0 )
{
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
}
2019-11-12 00:15:34 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facture set ref='(PROV-POS " . $_SESSION [ " takeposterminal " ] . " - " . $place . " )' where rowid= " . $placeid ;
2019-08-01 12:23:02 +02:00
$db -> query ( $sql );
}
2018-09-28 13:31:41 +02:00
}
2019-03-27 17:50:23 +01:00
if ( $action == " addline " )
{
2019-03-14 16:35:36 +01:00
$prod = new Product ( $db );
2018-12-07 17:02:06 +01:00
$prod -> fetch ( $idproduct );
2019-03-14 16:35:36 +01:00
2019-10-30 22:34:54 +01:00
$customer = new Societe ( $db );
$customer -> fetch ( $invoice -> socid );
2020-01-01 21:54:47 +01:00
$datapriceofproduct = $prod -> getSellPrice ( $mysoc , $customer , 0 );
2019-03-14 16:35:36 +01:00
2020-01-01 21:54:47 +01:00
$price = $datapriceofproduct [ 'pu_ht' ];
$price_ttc = $datapriceofproduct [ 'pu_ttc' ];
//$price_min = $datapriceofproduct['price_min'];
$price_base_type = $datapriceofproduct [ 'price_base_type' ];
$tva_tx = $datapriceofproduct [ 'tva_tx' ];
$tva_npr = $datapriceofproduct [ 'tva_npr' ];
// Local Taxes
$localtax1_tx = get_localtax ( $tva_tx , 1 , $customer , $mysoc , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $customer , $mysoc , $tva_npr );
2019-03-14 16:35:36 +01:00
2020-04-10 08:36:16 +02:00
$idoflineadded = $invoice -> addline ( $prod -> description , $price , 1 , $tva_tx , $localtax1_tx , $localtax2_tx , $idproduct , $customer -> remise_percent , '' , 0 , 0 , 0 , '' , $price_base_type , $price_ttc , $prod -> type , - 1 , 0 , '' , 0 , 0 , null , '' , '' , 0 , 100 , '' , null , 0 );
2018-12-07 17:02:06 +01:00
$invoice -> fetch ( $placeid );
2018-09-28 13:31:41 +02:00
}
2018-12-07 17:02:06 +01:00
if ( $action == " freezone " ) {
2019-08-27 21:57:21 +02:00
$customer = new Societe ( $db );
$customer -> fetch ( $invoice -> socid );
2020-01-01 21:54:47 +01:00
$tva_tx = get_default_tva ( $mysoc , $customer );
// Local Taxes
$localtax1_tx = get_localtax ( $tva_tx , 1 , $customer , $mysoc , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $customer , $mysoc , $tva_npr );
2020-04-10 08:36:16 +02:00
$invoice -> addline ( $desc , $number , 1 , $tva_tx , $localtax1_tx , $localtax2_tx , 0 , 0 , '' , 0 , 0 , 0 , '' , 'TTC' , $number , 0 , - 1 , 0 , '' , 0 , 0 , null , '' , '' , 0 , 100 , '' , null , 0 );
2018-12-07 17:02:06 +01:00
$invoice -> fetch ( $placeid );
2018-09-28 13:31:41 +02:00
}
2019-03-03 12:50:36 +01:00
if ( $action == " addnote " ) {
2019-11-12 00:15:34 +01:00
foreach ( $invoice -> lines as $line )
2019-03-03 12:50:36 +01:00
{
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 );
}
2018-12-07 17:02:06 +01:00
if ( $action == " deleteline " ) {
2019-04-02 17:36:27 +02:00
if ( $idline > 0 and $placeid > 0 ) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
2018-09-28 13:31:41 +02:00
$invoice -> deleteline ( $idline );
$invoice -> fetch ( $placeid );
}
2019-04-02 17:36:27 +02:00
elseif ( $placeid > 0 ) { // If invoice exists but no line selected, proceed to delete last line.
2019-11-12 00:15:34 +01:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " facturedet where fk_facture=' " . $placeid . " ' order by rowid DESC " ;
2018-09-28 13:31:41 +02:00
$resql = $db -> query ( $sql );
2018-12-07 17:02:06 +01:00
$row = $db -> fetch_array ( $resql );
$deletelineid = $row [ 0 ];
2018-09-28 13:31:41 +02:00
$invoice -> deleteline ( $deletelineid );
2018-10-18 16:31:37 +02:00
$invoice -> fetch ( $placeid );
2018-09-28 13:31:41 +02:00
}
}
2019-04-02 17:36:27 +02:00
if ( $action == " delete " ) {
2019-08-27 15:39:35 +02:00
// $placeid is the invoice id (it differs from place) and is defined if the place is set and the ref of invoice is '(PROV-POS'.$_SESSION["takeposterminal"].'-'.$place.')', so the fetch at begining of page works.
if ( $placeid > 0 ) {
2019-04-02 17:36:27 +02:00
$result = $invoice -> fetch ( $placeid );
2019-08-27 15:39:35 +02:00
if ( $result > 0 && $invoice -> statut == Facture :: STATUS_DRAFT )
2019-04-02 17:36:27 +02:00
{
2019-08-27 15:42:35 +02:00
$db -> begin ();
2019-08-27 15:39:35 +02:00
// We delete the lines
2019-11-12 00:15:34 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " facturedet_extrafields where fk_object = " . $placeid ;
2019-08-27 15:42:35 +02:00
$resql1 = $db -> query ( $sql );
2019-11-12 00:15:34 +01:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . " facturedet where fk_facture = " . $placeid ;
2019-08-27 15:42:35 +02:00
$resql2 = $db -> query ( $sql );
2019-11-12 00:15:34 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facture set fk_soc= " . $conf -> global -> { 'CASHDESK_ID_THIRDPARTY' . $_SESSION [ " takeposterminal " ]} . " where ref='(PROV-POS " . $_SESSION [ " takeposterminal " ] . " - " . $place . " )' " ;
2019-09-10 14:58:55 +02:00
$resql3 = $db -> query ( $sql );
2019-08-27 15:42:35 +02:00
2019-09-10 14:58:55 +02:00
if ( $resql1 && $resql2 && $resql3 )
2019-08-27 15:42:35 +02:00
{
$db -> commit ();
}
else
{
$db -> rollback ();
}
2019-04-02 17:36:27 +02:00
$invoice -> fetch ( $placeid );
}
}
}
2019-03-29 12:19:23 +01:00
if ( $action == " updateqty " )
{
2019-11-12 00:15:34 +01:00
foreach ( $invoice -> lines as $line )
2018-12-07 17:02:06 +01:00
{
2019-03-29 12:19:23 +01:00
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 );
2018-12-07 17:02:06 +01:00
}
2018-09-28 13:31:41 +02:00
}
2018-12-07 17:02:06 +01:00
$invoice -> fetch ( $placeid );
2018-09-28 13:31:41 +02:00
}
2019-03-29 12:19:23 +01:00
if ( $action == " updateprice " )
{
2019-11-12 00:15:34 +01:00
foreach ( $invoice -> lines as $line )
2018-12-07 17:02:06 +01:00
{
2019-10-01 20:36:24 +02:00
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 , 'TTC' , $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 );
2018-12-07 17:02:06 +01:00
}
2018-09-28 13:31:41 +02:00
}
2018-12-07 17:02:06 +01:00
$invoice -> fetch ( $placeid );
2018-09-28 13:31:41 +02:00
}
2019-03-29 12:19:23 +01:00
if ( $action == " updatereduction " )
{
2019-11-12 00:15:34 +01:00
foreach ( $invoice -> lines as $line )
2018-12-07 17:02:06 +01:00
{
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 );
}
2018-09-28 13:31:41 +02:00
}
2018-12-07 17:02:06 +01:00
$invoice -> fetch ( $placeid );
2018-09-28 13:31:41 +02:00
}
2019-03-29 12:19:23 +01:00
if ( $action == " order " and $placeid != 0 )
{
2019-11-12 00:15:34 +01:00
include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2018-12-07 17:02:06 +01:00
2019-11-12 00:15:34 +01:00
$headerorder = '<html><br><b>' . $langs -> trans ( 'Place' ) . ' ' . $place . '<br><table width="65%"><thead><tr><th class="left">' . $langs -> trans ( " Label " ) . '</th><th class="right">' . $langs -> trans ( " Qty " ) . '</th></tr></thead><tbody>' ;
$footerorder = '</tbody></table>' . dol_print_date ( dol_now (), 'dayhour' ) . '<br></html>' ;
2018-12-07 17:02:06 +01:00
$order_receipt_printer1 = " " ;
$order_receipt_printer2 = " " ;
$catsprinter1 = explode ( ';' , $conf -> global -> TAKEPOS_PRINTED_CATEGORIES_1 );
$catsprinter2 = explode ( ';' , $conf -> global -> TAKEPOS_PRINTED_CATEGORIES_2 );
2019-11-12 00:15:34 +01:00
foreach ( $invoice -> lines as $line )
2018-12-07 17:02:06 +01:00
{
2020-01-01 21:54:47 +01:00
if ( $line -> special_code == " 4 " ) {
continue ;
2018-12-07 17:02:06 +01:00
}
$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 ) {
2019-11-12 10:11:30 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='4' where rowid= " . $line -> id ;
2018-12-07 17:02:06 +01:00
$db -> query ( $sql );
2019-11-12 00:15:34 +01:00
$order_receipt_printer1 .= '<tr>' . $line -> product_label . '<td class="right">' . $line -> qty ;
if ( ! empty ( $line -> array_options [ 'options_order_notes' ])) $order_receipt_printer1 .= " <br>( " . $line -> array_options [ 'options_order_notes' ] . " ) " ;
$order_receipt_printer1 .= '</td></tr>' ;
2018-12-07 17:02:06 +01:00
}
2018-09-28 13:31:41 +02:00
}
2018-12-07 17:02:06 +01:00
2019-11-12 00:15:34 +01:00
foreach ( $invoice -> lines as $line )
2018-12-07 17:02:06 +01:00
{
2020-01-01 21:54:47 +01:00
if ( $line -> special_code == " 4 " ) {
continue ;
2018-12-07 17:02:06 +01:00
}
$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 ) {
2019-11-12 10:11:30 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='4' where rowid= " . $line -> id ;
2018-12-07 17:02:06 +01:00
$db -> query ( $sql );
2019-11-12 00:15:34 +01:00
$order_receipt_printer2 .= '<tr>' . $line -> product_label . '<td class="right">' . $line -> qty ;
if ( ! empty ( $line -> array_options [ 'options_order_notes' ])) $order_receipt_printer2 .= " <br>( " . $line -> array_options [ 'options_order_notes' ] . " ) " ;
$order_receipt_printer2 .= '</td></tr>' ;
2018-12-07 17:02:06 +01:00
}
2018-09-28 13:31:41 +02:00
}
2018-12-07 17:02:06 +01:00
$invoice -> fetch ( $placeid );
}
2018-09-28 13:31:41 +02:00
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink = '' ;
if ( $action == " valid " || $action == " history " )
2019-03-27 20:46:07 +01:00
{
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= '<!-- Section with invoice link -->' . " \n " ;
$sectionwithinvoicelink .= '<span style="font-size:120%;" class="center">' ;
$sectionwithinvoicelink .= $invoice -> getNomUrl ( 1 , '' , 0 , 0 , '' , 0 , 0 , - 1 , '_backoffice' ) . " - " ;
2019-03-31 11:25:29 +02:00
$remaintopay = $invoice -> getRemainToPay ();
if ( $remaintopay > 0 )
2019-03-27 20:46:07 +01:00
{
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= $langs -> trans ( 'RemainToPay' ) . ': <span class="amountremaintopay" style="font-size: unset">' . price ( $remaintopay , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</span>' ;
2019-03-27 20:46:07 +01:00
}
else
{
2019-11-12 00:15:34 +01:00
if ( $invoice -> paye ) $sectionwithinvoicelink .= '<span class="amountpaymentcomplete" style="font-size: unset">' . $langs -> trans ( " Paid " ) . '</span>' ;
else $sectionwithinvoicelink .= $langs -> trans ( 'BillShortStatusValidated' );
2019-03-27 20:46:07 +01:00
}
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= '</span>' ;
2019-11-03 00:50:58 +01:00
if ( $conf -> global -> TAKEPOSCONNECTOR ) {
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="TakeposPrinting(' . $placeid . ');">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2019-11-03 00:50:58 +01:00
} elseif ( $conf -> global -> TAKEPOS_DOLIBARR_PRINTER ) {
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="DolibarrTakeposPrinting(' . $placeid . ');">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2019-11-03 00:50:58 +01:00
} else {
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="Print(' . $placeid . ');">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2019-11-03 00:50:58 +01:00
}
2019-11-07 15:25:57 +01:00
if ( $conf -> global -> MAIN_FEATURES_LEVEL >= 2 )
{
2019-11-12 00:15:34 +01:00
$sectionwithinvoicelink .= ' <button id="buttonsend" type="button" onclick="SendTicket(' . $placeid . ');">' . $langs -> trans ( 'SendTicket' ) . '</button>' ;
2019-11-07 15:25:57 +01:00
}
2019-11-07 15:12:37 +01:00
2019-11-12 00:15:34 +01:00
if ( $conf -> global -> TAKEPOS_AUTO_PRINT_TICKETS ) $sectionwithinvoicelink .= '<script language="javascript">$("#buttonprint").click();</script>' ;
2019-10-23 22:05:37 +02:00
}
2019-03-27 15:42:53 +01:00
/*
* View
*/
2019-03-27 17:50:23 +01:00
$form = new Form ( $db );
2018-09-28 13:31:41 +02:00
?>
< script language = " javascript " >
var selectedline = 0 ;
var selectedtext = " " ;
2019-11-12 00:15:34 +01:00
var placeid =< ? php echo ( $placeid > 0 ? $placeid : 0 ); ?> ;
2019-03-27 17:50:23 +01:00
$ ( document ) . ready ( function () {
2019-11-12 00:15:34 +01:00
var idoflineadded = < ? php echo ( $idoflineadded ? $idoflineadded : 0 ); ?> ;
2019-03-29 12:19:23 +01:00
$ ( '.posinvoiceline' ) . click ( function (){
console . log ( " Click done on " + this . id );
$ ( '.posinvoiceline' ) . removeClass ( " selected " );
2018-09-28 13:31:41 +02:00
$ ( this ) . addClass ( " selected " );
2018-12-07 17:02:06 +01:00
if ( selectedline == this . id ) return ; // If is already selected
2019-03-29 12:19:23 +01:00
else selectedline = this . id ;
2018-09-28 13:31:41 +02:00
selectedtext = $ ( '#' + selectedline ) . find ( " td:first " ) . html ();
});
2019-03-29 12:19:23 +01:00
/* Autoselect the line */
if ( idoflineadded > 0 )
{
console . log ( " Auto select " + idoflineadded );
$ ( '.posinvoiceline#' + idoflineadded ) . click ();
}
2018-09-28 13:31:41 +02:00
< ? php
2018-12-07 08:04:40 +01:00
2018-12-07 17:02:06 +01:00
if ( $action == " order " and $order_receipt_printer1 != " " ) {
?>
$ . ajax ({
type : " POST " ,
2018-12-15 16:12:47 +01:00
url : 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print' ,
2018-12-07 17:02:06 +01:00
data : ' < ? php
2019-11-12 00:15:34 +01:00
print $headerorder . $order_receipt_printer1 . $footerorder ; ?> '
2018-12-07 17:02:06 +01:00
});
< ? php
2018-09-28 13:31:41 +02:00
}
2018-12-07 08:04:40 +01:00
2018-12-07 17:02:06 +01:00
if ( $action == " order " and $order_receipt_printer2 != " " ) {
?>
$ . ajax ({
type : " POST " ,
2018-12-15 16:12:47 +01:00
url : 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print2' ,
2018-12-07 17:02:06 +01:00
data : ' < ? php
2019-11-12 00:15:34 +01:00
print $headerorder . $order_receipt_printer2 . $footerorder ; ?> '
2018-12-07 17:02:06 +01:00
});
< ? php
}
2018-12-07 08:04:40 +01:00
2019-03-29 11:45:40 +01:00
// Set focus to search field
if ( $action == " search " || $action == " valid " ) {
2018-12-07 17:02:06 +01:00
?>
2019-03-29 11:45:40 +01:00
parent . setFocusOnSearchField ();
2018-12-07 17:02:06 +01:00
< ? php
}
2018-12-07 08:04:40 +01:00
2019-03-27 15:42:53 +01:00
2018-12-07 17:02:06 +01:00
if ( $action == " temp " and $ticket_printer1 != " " ) {
?>
$ . ajax ({
type : " POST " ,
2018-12-15 16:12:47 +01:00
url : 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print' ,
2018-12-07 17:02:06 +01:00
data : ' < ? php
2019-11-12 00:15:34 +01:00
print $header_soc . $header_ticket . $body_ticket . $ticket_printer1 . $ticket_total . $footer_ticket ; ?> '
2018-12-07 17:02:06 +01:00
});
< ? php
2018-09-28 13:31:41 +02:00
}
2018-12-07 00:40:00 +01:00
2018-12-07 17:02:06 +01:00
if ( $action == " search " ) {
?>
$ ( '#search' ) . focus ();
< ? php
2018-09-28 13:31:41 +02:00
}
2018-12-07 08:04:40 +01:00
2018-09-28 13:31:41 +02:00
?>
2019-03-27 17:50:23 +01:00
2018-09-28 13:31:41 +02:00
});
2019-11-07 15:25:57 +01:00
function SendTicket ( id )
2019-08-24 16:46:04 +02:00
{
console . log ( " Open box to select the Print/Send form " );
2019-11-12 00:15:34 +01:00
$ . colorbox ({ href : " send.php?facid= " + id , width : " 90% " , height : " 50% " , transition : " none " , iframe : " true " , title : " <?php echo $langs->trans ( " SendTicket " ); ?> " });
2019-08-24 16:46:04 +02:00
}
2018-09-28 13:31:41 +02:00
function Print ( id ){
2018-12-07 17:02:06 +01:00
$ . colorbox ({ href : " receipt.php?facid= " + id , width : " 40% " , height : " 90% " , transition : " none " , iframe : " true " , title : " <?php
echo $langs -> trans ( " PrintTicket " ); ?> "});
2018-09-28 13:31:41 +02:00
}
function TakeposPrinting ( id ){
2018-12-07 17:02:06 +01:00
var receipt ;
$ . get ( " receipt.php?facid= " + id , function ( data , status ){
2018-11-26 16:09:05 +01:00
receipt = data . replace ( / ([ ^> \r\n ] ? )( \r\n | \n\r | \r | \n ) / g , '' );
2018-12-07 17:02:06 +01:00
$ . ajax ({
type : " POST " ,
2018-12-15 16:12:47 +01:00
url : 'http://<?php print $conf->global->TAKEPOS_PRINT_SERVER; ?>:8111/print' ,
2018-12-07 17:02:06 +01:00
data : receipt
});
2018-09-28 13:31:41 +02:00
});
}
2019-11-03 00:50:58 +01:00
function DolibarrTakeposPrinting ( id ) {
2019-11-03 15:06:20 +01:00
console . log ( 'Printing invoice ticket ' + id )
$ . ajax ({
type : " GET " ,
url : " <?php print dol_buildpath('/takepos/ajax/ajax.php', 1).'?action=printinvoiceticket&term='. $_SESSION["takeposterminal"] .'&id='; ?> " + id ,
});
2019-11-03 00:50:58 +01:00
}
2018-09-28 13:31:41 +02:00
</ script >
2019-03-27 17:50:23 +01:00
2018-09-28 13:31:41 +02:00
< ? php
2019-03-27 17:50:23 +01:00
// Add again js for footer because this content is injected into takepos.php page so all init
// for tooltip and other js beautifiers must be reexecuted too.
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ))
2019-03-27 17:50:23 +01:00
{
print " \n " . '<!-- Includes JS Footer of Dolibarr -->' . " \n " ;
2019-11-12 00:15:34 +01:00
print '<script src="' . DOL_URL_ROOT . '/core/js/lib_foot.js.php?lang=' . $langs -> defaultlang . ( $ext ? '&' . $ext : '' ) . '"></script>' . " \n " ;
2019-03-27 17:50:23 +01:00
}
2019-03-27 20:13:12 +01:00
2018-12-07 21:33:40 +01:00
print '<div class="div-table-responsive-no-min invoice">' ;
2019-03-28 18:51:04 +01:00
print '<table id="tablelines" class="noborder noshadow postablelines" width="100%">' ;
2018-09-28 13:31:41 +02:00
print '<tr class="liste_titre nodrag nodrop">' ;
2019-03-27 20:13:12 +01:00
print '<td class="linecoldescription">' ;
print '<span style="font-size:120%;" class="right">' ;
if ( $conf -> global -> TAKEPOS_BAR_RESTAURANT )
{
2019-11-12 00:15:34 +01:00
$sql = " SELECT floor, label FROM " . MAIN_DB_PREFIX . " takepos_floor_tables where rowid= " . (( int ) $place );
2019-03-27 20:13:12 +01:00
$resql = $db -> query ( $sql );
$obj = $db -> fetch_object ( $resql );
if ( $obj )
{
$label = $obj -> label ;
$floor = $obj -> floor ;
}
2019-10-16 16:26:00 +02:00
// In phone version only show when is invoice page
2019-11-12 00:15:34 +01:00
if ( $mobilepage == " invoice " || $mobilepage == " " ) {
print $langs -> trans ( 'Place' ) . " <b> " . $label . " </b> - " ;
print $langs -> trans ( 'Floor' ) . " <b> " . $floor . " </b> - " ;
2019-10-16 16:26:00 +02:00
}
}
// In phone version only show when is invoice page
2019-11-12 00:15:34 +01:00
if ( $mobilepage == " invoice " || $mobilepage == " " ) {
2019-10-16 16:26:00 +02:00
print $langs -> trans ( 'TotalTTC' );
2019-11-12 00:15:34 +01:00
print ' : <b>' . price ( $invoice -> total_ttc , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</b></span>' ;
print '<br><input type="hidden" name="invoiceid" id="invoiceid" value="' . $invoice -> id . '">' . $sectionwithinvoicelink ;
2019-10-16 16:26:00 +02:00
print '</td>' ;
2019-03-27 20:13:12 +01:00
}
2019-11-12 00:15:34 +01:00
if ( $_SESSION [ " basiclayout " ] != 1 )
2019-05-26 16:44:17 +02:00
{
2019-11-12 00:15:34 +01:00
print '<td class="linecolqty right">' . $langs -> trans ( 'ReductionShort' ) . '</td>' ;
print '<td class="linecolqty right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
print '<td class="linecolht right nowraponall">' . $langs -> trans ( 'TotalTTCShort' ) . '</td>' ;
2019-05-26 16:44:17 +02:00
}
2018-09-28 13:31:41 +02:00
print " </tr> \n " ;
2018-12-07 08:04:40 +01:00
2020-01-01 21:54:47 +01:00
2019-11-12 00:15:34 +01:00
if ( $_SESSION [ " basiclayout " ] == 1 )
2019-05-26 16:44:17 +02:00
{
2019-11-12 00:15:34 +01:00
if ( $mobilepage == " cats " )
2019-05-26 16:44:17 +02:00
{
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$categorie = new Categorie ( $db );
$categories = $categorie -> get_full_arbo ( 'product' );
$htmlforlines = '' ;
2019-11-12 00:15:34 +01:00
foreach ( $categories as $row ) {
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline' ;
$htmlforlines .= '" onclick="LoadProducts(' . $row [ 'id' ] . ');">' ;
$htmlforlines .= '<td class="left">' ;
$htmlforlines .= $row [ 'label' ];
$htmlforlines .= '</td>' ;
$htmlforlines .= '</tr>' . " \n " ;
2019-05-26 16:44:17 +02:00
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</table>' ;
$htmlforlines .= '</table>' ;
2019-05-26 16:44:17 +02:00
print $htmlforlines ;
}
2019-08-26 16:49:25 +02:00
2019-11-12 00:15:34 +01:00
if ( $mobilepage == " products " )
2019-05-26 16:44:17 +02:00
{
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$object = new Categorie ( $db );
$catid = GETPOST ( 'catid' , 'int' );
2019-11-12 00:15:34 +01:00
$result = $object -> fetch ( $catid );
2019-05-26 16:44:17 +02:00
$prods = $object -> getObjectsInCateg ( " product " );
$htmlforlines = '' ;
foreach ( $prods as $row ) {
2019-11-12 00:15:34 +01:00
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline' ;
$htmlforlines .= '" onclick="AddProduct(\'' . $place . '\', ' . $row -> id . ')">' ;
$htmlforlines .= '<td class="left">' ;
$htmlforlines .= $row -> label ;
$htmlforlines .= '</td>' ;
$htmlforlines .= '</tr>' . " \n " ;
2019-05-26 16:44:17 +02:00
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</table>' ;
2019-05-26 16:44:17 +02:00
print $htmlforlines ;
}
2019-08-26 16:49:25 +02:00
2019-11-12 00:15:34 +01:00
if ( $mobilepage == " places " )
2019-05-26 16:44:17 +02:00
{
2019-11-12 00:15:34 +01:00
$sql = " SELECT rowid, entity, label, leftpos, toppos, floor FROM " . MAIN_DB_PREFIX . " takepos_floor_tables " ;
2019-05-26 16:44:17 +02:00
$resql = $db -> query ( $sql );
$rows = array ();
$htmlforlines = '' ;
2019-11-12 00:15:34 +01:00
while ( $row = $db -> fetch_array ( $resql )) {
2019-05-26 16:44:17 +02:00
$rows [] = $row ;
2019-11-12 00:15:34 +01:00
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline' ;
$htmlforlines .= '" onclick="LoadPlace(\'' . $row [ 'label' ] . '\')">' ;
$htmlforlines .= '<td class="left">' ;
$htmlforlines .= $row [ 'label' ];
$htmlforlines .= '</td>' ;
$htmlforlines .= '</tr>' . " \n " ;
2019-05-26 16:44:17 +02:00
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</table>' ;
2019-05-26 16:44:17 +02:00
print $htmlforlines ;
}
}
2019-03-27 20:13:12 +01:00
if ( $placeid > 0 )
{
2019-10-16 16:26:00 +02:00
//In Phone basic layout hide some content depends situation
2019-11-12 00:15:34 +01:00
if ( $_SESSION [ " basiclayout " ] == 1 && $mobilepage != " invoice " && $action != " order " ) return ;
2019-10-20 15:37:20 +02:00
2019-03-27 20:20:39 +01:00
if ( is_array ( $invoice -> lines ) && count ( $invoice -> lines ))
2018-12-07 17:02:06 +01:00
{
2019-03-27 20:20:39 +01:00
$tmplines = array_reverse ( $invoice -> lines );
2019-11-12 00:15:34 +01:00
foreach ( $tmplines as $line )
2019-03-27 17:50:23 +01:00
{
2019-03-27 20:20:39 +01:00
$htmlforlines = '' ;
2019-11-12 00:15:34 +01:00
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline' ;
2019-07-19 10:44:12 +02:00
if ( $line -> special_code == " 4 " ) {
2019-11-12 00:15:34 +01:00
$htmlforlines .= ' order' ;
2019-03-27 17:50:23 +01:00
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '" id="' . $line -> id . '">' ;
$htmlforlines .= '<td class="left">' ;
2019-03-28 18:51:04 +01:00
//if ($line->product_label) $htmlforlines.= '<b>'.$line->product_label.'</b>';
if ( isset ( $line -> product_type ))
{
2019-11-12 00:15:34 +01:00
if ( empty ( $line -> product_type )) $htmlforlines .= img_object ( '' , 'product' ) . ' ' ;
else $htmlforlines .= img_object ( '' , 'service' ) . ' ' ;
2019-03-28 18:51:04 +01:00
}
2019-11-12 00:15:34 +01:00
if ( $line -> product_label ) $htmlforlines .= $line -> product_label ;
if ( $line -> product_label && $line -> desc ) $htmlforlines .= '<br>' ;
2019-03-27 20:20:39 +01:00
if ( $line -> product_label != $line -> desc )
2019-03-27 17:50:23 +01:00
{
2019-03-27 20:20:39 +01:00
$firstline = dolGetFirstLineOfText ( $line -> desc );
if ( $firstline != $line -> desc )
{
2019-11-12 00:15:34 +01:00
$htmlforlines .= $form -> textwithpicto ( dolGetFirstLineOfText ( $line -> desc ), $line -> desc );
2019-03-27 20:20:39 +01:00
}
else
{
2019-11-12 00:15:34 +01:00
$htmlforlines .= $line -> desc ;
2019-03-27 20:20:39 +01:00
}
2019-03-27 17:50:23 +01:00
}
2019-11-12 00:15:34 +01:00
if ( ! empty ( $line -> array_options [ 'options_order_notes' ])) $htmlforlines .= " <br>( " . $line -> array_options [ 'options_order_notes' ] . " ) " ;
if ( $_SESSION [ " basiclayout " ] != 1 )
2019-05-26 16:44:17 +02:00
{
2020-01-01 21:54:47 +01:00
$moreinfo = '' ;
$moreinfo .= $langs -> transcountry ( " TotalHT " , $mysoc -> country_code ) . ': ' . price ( $line -> total_ht );
if ( $line -> vat_src_code ) $moreinfo .= '<br>' . $langs -> trans ( " VATCode " ) . ': ' . $line -> vat_src_code ;
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalVAT " , $mysoc -> country_code ) . ': ' . price ( $line -> total_vat );
//$moreinfo .= '<br>'.$langs->transcountry("VATRate", $mysoc->country_code).': '.price($line->);
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalLT1 " , $mysoc -> country_code ) . ': ' . price ( $line -> total_localtax1 );
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalLT2 " , $mysoc -> country_code ) . ': ' . price ( $line -> total_localtax2 );
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalTTC " , $mysoc -> country_code ) . ': ' . price ( $line -> total_ttc );
//$moreinfo .= $langs->trans("TotalHT").': '.$line->total_ht;
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</td>' ;
$htmlforlines .= '<td class="right">' . vatrate ( $line -> remise_percent , true ) . '</td>' ;
$htmlforlines .= '<td class="right">' . $line -> qty . '</td>' ;
2020-01-01 21:54:47 +01:00
$htmlforlines .= '<td class="right classfortooltip" title="' . $moreinfo . '">' . price ( $line -> total_ttc ) . '</td>' ;
2019-05-26 16:44:17 +02:00
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</tr>' . " \n " ;
2019-03-27 20:20:39 +01:00
print $htmlforlines ;
2019-03-27 17:50:23 +01:00
}
2019-03-27 20:20:39 +01:00
}
else
{
print '<tr class="drag drop oddeven"><td class="left"><span class="opacitymedium">' . $langs -> trans ( " Empty " ) . '</span></td><td></td><td></td><td></td></tr>' ;
2018-12-07 17:02:06 +01:00
}
2018-09-28 13:31:41 +02:00
}
2019-03-28 09:56:01 +01:00
else { // No invoice generated yet
print '<tr class="drag drop oddeven"><td class="left"><span class="opacitymedium">' . $langs -> trans ( " Empty " ) . '</span></td><td></td><td></td><td></td></tr>' ;
}
2018-12-07 08:04:40 +01:00
2018-09-28 13:31:41 +02:00
print '</table>' ;
2018-12-07 08:04:40 +01:00
2020-01-01 21:54:47 +01:00
if ( $invoice -> socid != $conf -> global -> $constforcompanyid )
2018-12-16 19:24:49 +01:00
{
2019-10-20 15:37:20 +02:00
print '<!-- Show customer -->' ;
print '<p class="right">' ;
2018-09-28 13:31:41 +02:00
print $langs -> trans ( " Customer " ) . ': ' . $soc -> name ;
2019-09-15 21:01:29 +02:00
$constantforkey = 'CASHDESK_NO_DECREASE_STOCK' . $_SESSION [ " takeposterminal " ];
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> stock -> enabled ) && $conf -> global -> $constantforkey != " 1 " )
2019-09-15 21:01:29 +02:00
{
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
$warehouse = new Entrepot ( $db );
$warehouse -> fetch ( $conf -> global -> $constantforkey );
print '<br>' . $langs -> trans ( " Warehouse " ) . ': ' . $warehouse -> ref ;
}
2019-10-09 18:15:59 +02:00
// Module Adherent
2019-11-12 00:15:34 +01:00
if ( ! empty ( $conf -> adherent -> enabled ))
2019-10-09 18:15:59 +02:00
{
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
$langs -> load ( " members " );
2019-10-20 15:37:20 +02:00
print '<br>' . $langs -> trans ( " Member " ) . ': ' ;
2019-11-12 00:15:34 +01:00
$adh = new Adherent ( $db );
$result = $adh -> fetch ( '' , '' , $invoice -> socid );
2019-10-09 18:15:59 +02:00
if ( $result > 0 )
2019-09-15 21:01:29 +02:00
{
2019-11-12 00:15:34 +01:00
$adh -> ref = $adh -> getFullName ( $langs );
2019-10-09 18:15:59 +02:00
print $adh -> getFullName ( $langs );
print '<br>' . $langs -> trans ( " Type " ) . ': ' . $adh -> type ;
if ( $adh -> datefin )
2019-09-15 21:01:29 +02:00
{
2019-10-09 18:15:59 +02:00
print '<br>' . $langs -> trans ( " SubscriptionEndDate " ) . ': ' . dol_print_date ( $adh -> datefin , 'day' );
if ( $adh -> hasDelay ()) {
print " " . img_warning ( $langs -> trans ( " Late " ));
}
2019-09-15 21:01:29 +02:00
}
else
{
2019-10-09 18:15:59 +02:00
print '<br>' . $langs -> trans ( " SubscriptionNotReceived " );
if ( $adh -> statut > 0 ) print " " . img_warning ( $langs -> trans ( " Late " )); // displays delay Pictogram only if not a draft and not terminated
2019-09-15 21:01:29 +02:00
}
}
2019-10-09 18:15:59 +02:00
else
{
print '<span class="opacitymedium">' . $langs -> trans ( " ThirdpartyNotLinkedToMember " ) . '</span>' ;
}
}
2019-10-20 15:37:20 +02:00
print '</p>' ;
2018-12-16 19:24:49 +01:00
}
2019-03-27 15:42:53 +01:00
2018-12-16 19:24:49 +01:00
if ( $action == " search " )
{
2018-12-07 17:02:06 +01:00
print ' < center >
2019-11-12 00:15:34 +01:00
< input type = " text " id = " search " name = " search " onkeyup = " Search2(); " name = " search " style = " width:80%;font-size: 150%; " placeholder = ' . $langs->trans(' Search ').'
2018-09-28 13:31:41 +02:00
</ center > ' ;
}
2018-12-07 08:04:40 +01:00
2018-09-28 13:31:41 +02:00
print '</div>' ;