2018-09-28 13:31:41 +02:00
< ? php
2018-12-07 17:02:06 +01:00
/**
2024-09-20 01:46:07 +02:00
* Copyright ( C ) 2018 Andreu Bisquerra < jove @ bisquerra . com >
* Copyright ( C ) 2021 Nicolas ZABOURI < info @ inovea - conseil . com >
* Copyright ( C ) 2022 - 2023 Christophe Battarel < christophe . battarel @ altairis . fr >
2025-02-18 21:48:21 +01:00
* Copyright ( C ) 2024 - 2025 MDW < mdeweerd @ users . noreply . github . com >
2024-09-20 01:46:07 +02:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
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
/**
2022-09-08 20:16:22 +02:00
* \file htdocs / takepos / invoice . php
* \ingroup takepos
* \brief Page to generate section with list of lines
2019-03-28 09:56:01 +01:00
*/
2022-09-08 20:16:22 +02: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');
2021-02-26 21:17:52 +01:00
if ( ! defined ( 'NOTOKENRENEWAL' )) {
define ( 'NOTOKENRENEWAL' , '1' );
}
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
2022-09-08 20:16:22 +02:00
// Load Dolibarr environment
2021-02-26 21:17:52 +01:00
if ( ! defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
require '../main.inc.php' ;
}
2019-11-12 00:15:34 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2022-05-03 09:44:18 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php' ;
2022-09-08 20:16:22 +02:00
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php' ;
2023-10-13 16:19:10 +02:00
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php' ;
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
2024-11-06 19:39:46 +01:00
* @ var Societe $mysoc
2024-11-04 23:53:20 +01:00
* @ var Translate $langs
* @ var User $user
*/
2022-09-08 20:16:22 +02:00
2022-05-03 09:35:06 +02:00
$hookmanager -> initHooks ( array ( 'takeposinvoice' ));
2018-12-07 08:04:40 +01:00
2020-06-29 17:58:04 +02:00
$langs -> loadLangs ( array ( " companies " , " commercial " , " bills " , " cashdesk " , " stocks " , " banks " ));
2019-03-14 16:35:36 +01:00
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2024-02-22 19:18:00 +01:00
$idproduct = GETPOSTINT ( 'idproduct' );
2020-03-23 15:02:15 +01:00
$place = ( GETPOST ( 'place' , 'aZ09' ) ? GETPOST ( 'place' , 'aZ09' ) : 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
2022-04-08 00:42:39 +02:00
$mobilepage = GETPOST ( 'mobilepage' , 'alpha' );
2020-12-04 00:58:51 +01:00
// Terminal is stored into $_SESSION["takeposterminal"];
2019-03-27 20:13:12 +01:00
2023-10-15 18:41:39 +02:00
if ( ! $user -> hasRight ( 'takepos' , 'run' ) && ! defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
2024-01-07 13:38:13 +01:00
accessforbidden ( 'No permission to use the TakePOS' );
2020-03-16 19:23:18 +01:00
}
2021-07-08 12:17:32 +02:00
if (( getDolGlobalString ( 'TAKEPOS_PHONE_BASIC_LAYOUT' ) == 1 && $conf -> browser -> layout == 'phone' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
2019-05-26 16:44:17 +02:00
// DIRECT LINK TO THIS PAGE FROM MOBILE AND NO TERMINAL SELECTED
2021-02-26 21:17:52 +01:00
if ( $_SESSION [ " takeposterminal " ] == " " ) {
2021-07-08 12:17:32 +02:00
if ( getDolGlobalString ( 'TAKEPOS_NUM_TERMINALS' ) == " 1 " ) {
2021-02-26 21:17:52 +01:00
$_SESSION [ " takeposterminal " ] = 1 ;
} else {
2020-03-16 15:41:21 +01:00
header ( " Location: " . DOL_URL_ROOT . " /takepos/index.php " );
2019-05-26 16:44:17 +02:00
exit ;
}
}
}
2024-02-24 12:45:37 +01:00
$takeposterminal = isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' ;
2022-08-22 00:04:04 +02:00
2019-03-22 09:06:44 +01:00
/**
2024-01-12 17:18:52 +01:00
* Abort invoice creation with a given error message
2019-03-22 09:06:44 +01:00
*
* @ param string $message Message explaining the error to the user
2025-02-18 21:48:21 +01:00
* @ return never
2019-03-22 09:06:44 +01:00
*/
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 );
}
2025-02-18 21:48:21 +01:00
$number = ( float ) GETPOST ( 'number' , 'alpha' );
2024-02-22 19:18:00 +01:00
$idline = GETPOSTINT ( 'idline' );
$selectedline = GETPOSTINT ( 'selectedline' );
2020-09-16 17:56:26 +02:00
$desc = GETPOST ( 'desc' , 'alphanohtml' );
$pay = GETPOST ( 'pay' , 'aZ09' );
2024-02-22 19:18:00 +01:00
$amountofpayment = GETPOSTFLOAT ( 'amount' );
2018-12-07 08:04:40 +01:00
2024-02-22 19:18:00 +01:00
$invoiceid = GETPOSTINT ( 'invoiceid' );
2019-03-14 16:35:36 +01:00
2019-03-26 20:01:06 +01:00
$paycode = $pay ;
2021-02-26 21:17:52 +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
2021-07-08 12:17:32 +02:00
$paiementid = 0 ;
if ( $paycode ) {
$sql = " SELECT id FROM " . MAIN_DB_PREFIX . " c_paiement " ;
$sql .= " WHERE entity IN ( " . getEntity ( 'c_paiement' ) . " ) " ;
$sql .= " AND code = ' " . $db -> escape ( $paycode ) . " ' " ;
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$paiementid = $obj -> id ;
}
}
}
2019-03-27 12:40:32 +01:00
2019-03-27 15:42:53 +01:00
$invoice = new Facture ( $db );
2021-02-26 21:17:52 +01:00
if ( $invoiceid > 0 ) {
2020-09-07 10:18:17 +02:00
$ret = $invoice -> fetch ( $invoiceid );
2020-05-21 15:05:19 +02:00
} else {
2025-02-18 21:48:21 +01:00
$ret = $invoice -> fetch ( 0 , '(PROV-POS' . $takeposterminal . '-' . $place . ')' );
2019-03-27 15:42:53 +01:00
}
2021-02-26 21:17:52 +01:00
if ( $ret > 0 ) {
2020-09-07 10:18:17 +02:00
$placeid = $invoice -> id ;
2019-03-27 15:42:53 +01:00
}
2024-02-24 12:45:37 +01:00
$constforcompanyid = 'CASHDESK_ID_THIRDPARTY' . $takeposterminal ;
2020-01-01 21:54:47 +01:00
$soc = new Societe ( $db );
2021-02-26 21:17:52 +01:00
if ( $invoice -> socid > 0 ) {
$soc -> fetch ( $invoice -> socid );
} else {
2025-02-18 21:48:21 +01:00
$soc -> fetch ( getDolGlobalInt ( $constforcompanyid ));
2021-02-26 21:17:52 +01:00
}
2020-01-01 21:54:47 +01:00
2024-02-24 12:45:37 +01:00
// Assign a default project, if relevant
if ( isModEnabled ( 'project' ) && getDolGlobalInt ( " CASHDESK_ID_PROJECT " . $takeposterminal )) {
$invoice -> fk_project = getDolGlobalInt ( " CASHDESK_ID_PROJECT " . $takeposterminal );
}
2021-07-06 03:53:42 +02:00
// Change the currency of invoice if it was modified
2022-08-26 17:03:20 +02:00
if ( isModEnabled ( 'multicurrency' ) && ! empty ( $_SESSION [ " takeposcustomercurrency " ])) {
2021-07-06 03:53:42 +02:00
if ( $invoice -> multicurrency_code != $_SESSION [ " takeposcustomercurrency " ]) {
$invoice -> setMulticurrencyCode ( $_SESSION [ " takeposcustomercurrency " ]);
}
}
2024-02-06 17:05:52 +01:00
$term = empty ( $_SESSION [ " takeposterminal " ]) ? 1 : $_SESSION [ " takeposterminal " ];
2022-07-07 22:35:56 +02:00
2022-05-03 09:35:06 +02:00
/*
* Actions
*/
2024-11-10 11:16:23 +01:00
$error = 0 ;
2024-03-07 20:16:48 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'doActions' , $parameters , $invoice , $action ); // Note that $action and $object may have been modified by some hooks
2023-12-04 13:53:48 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2021-07-06 03:53:42 +02:00
2025-02-18 21:48:21 +01:00
$sectionwithinvoicelink = '' ;
$CUSTOMER_DISPLAY_line1 = '' ;
$CUSTOMER_DISPLAY_line2 = '' ;
$headerorder = '' ;
$footerorder = '' ;
$printer = null ;
$idoflineadded = 0 ;
2022-05-03 09:35:06 +02:00
if ( empty ( $reshook )) {
// Action to record a payment on a TakePOS invoice
2023-02-14 22:56:12 +01:00
if ( $action == 'valid' && $user -> hasRight ( 'facture' , 'creer' )) {
2022-05-03 09:35:06 +02:00
$bankaccount = 0 ;
$error = 0 ;
2020-06-29 17:58:04 +02:00
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'TAKEPOS_CAN_FORCE_BANK_ACCOUNT_DURING_PAYMENT' )) {
2024-01-25 12:22:09 +01:00
$bankaccount = GETPOSTINT ( 'accountid' );
2021-02-26 21:17:52 +01:00
} else {
2022-05-03 09:35:06 +02:00
if ( $pay == 'LIQ' ) {
2024-01-25 12:22:09 +01:00
$bankaccount = getDolGlobalInt ( 'CASHDESK_ID_BANKACCOUNT_CASH' . $_SESSION [ " takeposterminal " ]); // For backward compatibility
2022-05-03 09:35:06 +02:00
} elseif ( $pay == " CHQ " ) {
2024-01-25 12:22:09 +01:00
$bankaccount = getDolGlobalInt ( 'CASHDESK_ID_BANKACCOUNT_CHEQUE' . $_SESSION [ " takeposterminal " ]); // For backward compatibility
2022-05-03 09:35:06 +02:00
} else {
$accountname = " CASHDESK_ID_BANKACCOUNT_ " . $pay . $_SESSION [ " takeposterminal " ];
2024-01-25 12:22:09 +01:00
$bankaccount = getDolGlobalInt ( $accountname );
2022-05-03 09:35:06 +02:00
}
2020-09-07 10:18:17 +02:00
}
2020-06-29 17:58:04 +02:00
2024-02-27 15:30:37 +01:00
if ( $bankaccount <= 0 && $pay != " delayed " && isModEnabled ( " bank " )) {
2022-05-03 09:35:06 +02:00
$errormsg = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " BankAccount " ));
$error ++ ;
}
2020-06-29 17:58:04 +02:00
2022-05-03 09:35:06 +02:00
$now = dol_now ();
$res = 0 ;
2019-03-14 16:35:36 +01:00
2022-05-03 09:35:06 +02:00
$invoice = new Facture ( $db );
$invoice -> fetch ( $placeid );
2020-06-29 17:58:04 +02:00
2024-04-30 12:42:10 +02:00
$db -> begin ();
2022-05-03 09:35:06 +02:00
if ( $invoice -> total_ttc < 0 ) {
$invoice -> type = $invoice :: TYPE_CREDIT_NOTE ;
2020-12-30 22:58:40 +01:00
2024-03-31 13:56:44 +02:00
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " facture " ;
$sql .= " WHERE entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
$sql .= " AND fk_soc = " . (( int ) $invoice -> socid );
2022-05-03 09:35:06 +02:00
$sql .= " AND type <> " . Facture :: TYPE_CREDIT_NOTE ;
$sql .= " AND fk_statut >= " . $invoice :: STATUS_VALIDATED ;
$sql .= " ORDER BY rowid DESC " ;
2020-12-30 22:58:40 +01:00
2025-02-18 21:48:21 +01:00
$fk_source = 0 ;
2022-05-03 09:35:06 +02:00
$resql = $db -> query ( $sql );
if ( $resql ) {
$obj = $db -> fetch_object ( $resql );
$fk_source = $obj -> rowid ;
2025-02-18 21:48:21 +01:00
if (( int ) $fk_source == 0 ) {
2022-05-03 09:35:06 +02:00
fail ( $langs -> transnoentitiesnoconv ( " NoPreviousBillForCustomer " ));
}
} else {
2019-03-22 09:06:44 +01:00
fail ( $langs -> transnoentitiesnoconv ( " NoPreviousBillForCustomer " ));
}
2022-05-03 09:35:06 +02:00
$invoice -> fk_facture_source = $fk_source ;
$invoice -> update ( $user );
}
2023-10-09 15:44:57 +02:00
$constantforkey = 'CASHDESK_NO_DECREASE_STOCK' . ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' );
2024-08-29 19:45:11 +02:00
$allowstockchange = ( getDolGlobalString ( $constantforkey ) != " 1 " );
2022-05-03 09:35:06 +02:00
if ( $error ) {
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $errormsg , [], 1 );
2024-04-30 12:42:10 +02:00
} elseif ( $invoice -> status != Facture :: STATUS_DRAFT ) {
2022-05-03 09:35:06 +02:00
//If invoice is validated but it is not fully paid is not error and make the payment
if ( $invoice -> getRemainToPay () > 0 ) {
$res = 1 ;
} else {
dol_syslog ( " Sale already validated " );
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $langs -> trans ( " InvoiceIsAlreadyValidated " , " TakePos " ), [], 1 );
2022-05-03 09:35:06 +02:00
}
} elseif ( count ( $invoice -> lines ) == 0 ) {
$error ++ ;
dol_syslog ( 'Sale without lines' );
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $langs -> trans ( " NoLinesToBill " , " TakePos " ), [], 1 );
2024-08-29 19:45:11 +02:00
} elseif ( isModEnabled ( 'stock' ) && ! isModEnabled ( 'productbatch' ) && $allowstockchange ) {
// Validation of invoice with change into stock when produt/lot module is NOT enabled and stock change NOT disabled.
2024-04-30 12:42:10 +02:00
// The case for isModEnabled('productbatch') is processed few lines later.
2024-01-05 04:18:53 +01:00
$savconst = getDolGlobalString ( 'STOCK_CALCULATE_ON_BILL' );
2023-10-10 11:51:52 +02:00
2024-08-29 19:45:11 +02:00
$conf -> global -> STOCK_CALCULATE_ON_BILL = 1 ; // To force the change of stock during invoice validation
2022-05-03 09:35:06 +02:00
2024-11-22 12:29:00 +01:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' );
2024-08-29 19:45:11 +02:00
dol_syslog ( " Validate invoice with stock change. Warehouse defined into constant " . $constantforkey . " = " . getDolGlobalString ( $constantforkey ));
2024-04-30 12:42:10 +02:00
2024-08-29 19:45:11 +02:00
// Validate invoice with stock change into warehouse getDolGlobalInt($constantforkey)
// Label of stock movement will be the same as when we validate invoice "Invoice XXXX validated"
2024-08-29 21:03:53 +02:00
$batch_rule = 0 ; // Module productbatch is disabled here, so no need for a batch_rule.
2024-04-30 12:42:10 +02:00
$res = $invoice -> validate ( $user , '' , getDolGlobalInt ( $constantforkey ), 0 , $batch_rule );
2020-02-27 18:13:26 +01:00
2024-08-29 19:45:11 +02:00
// Restore setup
2022-05-03 09:35:06 +02:00
$conf -> global -> STOCK_CALCULATE_ON_BILL = $savconst ;
2020-06-29 17:58:04 +02:00
} else {
2024-08-29 19:45:11 +02:00
// Validation of invoice with no change into stock (because param $idwarehouse is not fill)
2022-05-03 09:35:06 +02:00
$res = $invoice -> validate ( $user );
if ( $res < 0 ) {
$error ++ ;
2022-07-07 22:35:56 +02:00
$langs -> load ( " admin " );
2023-12-04 13:53:48 +01:00
dol_htmloutput_errors ( $invoice -> error == 'NotConfigured' ? $langs -> trans ( " NotConfigured " ) . ' (TakePos numbering module)' : $invoice -> error , $invoice -> errors , 1 );
2022-05-03 09:35:06 +02:00
}
2020-12-04 00:58:51 +01:00
}
2020-02-27 18:13:26 +01:00
2022-05-03 09:35:06 +02:00
// Add the payment
if ( ! $error && $res >= 0 ) {
$remaintopay = $invoice -> getRemainToPay ();
if ( $remaintopay > 0 ) {
$payment = new Paiement ( $db );
2024-12-09 14:07:37 +01:00
2022-05-03 09:35:06 +02:00
$payment -> datepaye = $now ;
$payment -> fk_account = $bankaccount ;
if ( $pay == 'LIQ' ) {
2024-02-22 19:18:00 +01:00
$payment -> pos_change = GETPOSTFLOAT ( 'excess' );
2022-05-03 09:35:06 +02:00
}
2020-09-30 15:09:45 +02:00
2024-12-09 14:07:37 +01:00
$payment -> amounts [ $invoice -> id ] = $amountofpayment ;
2022-05-03 09:35:06 +02:00
// If user has not used change control, add total invoice payment
// Or if user has used change control and the amount of payment is higher than remain to pay, add the remain to pay
2023-06-10 10:41:38 +02:00
if ( $amountofpayment <= 0 || $amountofpayment > $remaintopay ) {
2022-05-03 09:35:06 +02:00
$payment -> amounts [ $invoice -> id ] = $remaintopay ;
}
2024-12-09 14:07:37 +01:00
// We do not set $payments->multicurrency_amounts because we want payment to be in main currency.
2020-10-01 19:35:49 +02:00
2022-05-03 09:35:06 +02:00
$payment -> paiementid = $paiementid ;
$payment -> num_payment = $invoice -> ref ;
2020-09-30 15:09:45 +02:00
2022-05-03 09:35:06 +02:00
if ( $pay != " delayed " ) {
2024-12-09 14:07:37 +01:00
$res = $payment -> create ( $user );
if ( $res < 0 ) {
$error ++ ;
dol_htmloutput_errors ( $langs -> trans ( 'Error' ) . ' ' . $payment -> error , $payment -> errors , 1 );
}
2024-12-09 11:20:35 +01:00
2024-02-07 17:44:39 +01:00
$res = $payment -> addPaymentToBank ( $user , 'payment' , '(CustomerInvoicePayment)' , $bankaccount , '' , '' );
2024-02-01 12:14:30 +01:00
if ( $res < 0 ) {
$error ++ ;
2024-12-09 11:20:35 +01:00
dol_htmloutput_errors ( $langs -> trans ( 'ErrorNoPaymentDefined' ) . ' ' . $payment -> error , $payment -> errors , 1 );
2024-02-01 12:14:30 +01:00
}
2022-05-03 09:35:06 +02:00
$remaintopay = $invoice -> getRemainToPay (); // Recalculate remain to pay after the payment is recorded
2023-05-21 18:50:16 +02:00
} elseif ( getDolGlobalInt ( " TAKEPOS_DELAYED_TERMS " )) {
2023-05-19 17:21:36 +02:00
$invoice -> setPaymentTerms ( getDolGlobalInt ( " TAKEPOS_DELAYED_TERMS " ));
2022-05-03 09:35:06 +02:00
}
2020-10-01 19:43:23 +02:00
}
2019-09-24 10:08:48 +02:00
2022-05-03 09:35:06 +02:00
if ( $remaintopay == 0 ) {
dol_syslog ( " Invoice is paid, so we set it to status Paid " );
$result = $invoice -> setPaid ( $user );
if ( $result > 0 ) {
$invoice -> paye = 1 ;
2024-12-09 11:20:35 +01:00
$invoice -> status = $invoice :: STATUS_CLOSED ;
2022-05-03 09:35:06 +02:00
}
// set payment method
$invoice -> setPaymentMethods ( $paiementid );
} else {
dol_syslog ( " Invoice is not paid, remain to pay = " . $remaintopay );
2021-02-26 21:17:52 +01:00
}
2019-09-24 10:08:48 +02:00
} else {
2022-05-03 09:35:06 +02:00
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
2019-09-24 10:08:48 +02:00
}
2024-04-30 12:42:10 +02:00
2025-02-18 21:48:21 +01:00
$warehouseid = 0 ;
2023-11-11 12:23:12 +01:00
// Update stock for batch products
2024-04-30 12:42:10 +02:00
if ( ! $error && $res >= 0 ) {
2024-08-29 19:45:11 +02:00
if ( isModEnabled ( 'stock' ) && isModEnabled ( 'productbatch' ) && $allowstockchange ) {
// Update stocks
2024-08-29 21:48:54 +02:00
dol_syslog ( " Now we record the stock movement for each qualified line " );
2024-08-29 19:45:11 +02:00
// The case !isModEnabled('productbatch') was processed few lines before.
2024-04-30 12:42:10 +02:00
require_once DOL_DOCUMENT_ROOT . " /product/stock/class/mouvementstock.class.php " ;
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
$inventorycode = dol_print_date ( dol_now (), 'dayhourlog' );
2024-08-29 19:45:11 +02:00
// Label of stock movement will be "TakePOS - Invoice XXXX"
2024-04-30 12:42:10 +02:00
$labeltakeposmovement = 'TakePOS - ' . $langs -> trans ( " Invoice " ) . ' ' . $invoice -> ref ;
foreach ( $invoice -> lines as $line ) {
2024-08-29 19:45:11 +02:00
// Use the warehouse id defined on invoice line else in the setup
2024-04-30 12:42:10 +02:00
$warehouseid = ( $line -> fk_warehouse ? $line -> fk_warehouse : getDolGlobalInt ( $constantforkey ));
// var_dump('fk_product='.$line->fk_product.' batch='.$line->batch.' warehouse='.$line->fk_warehouse.' qty='.$line->qty);
if ( $line -> batch != '' && $warehouseid > 0 ) {
$prod_batch = new Productbatch ( $db );
$prod_batch -> find ( 0 , '' , '' , $line -> batch , $warehouseid );
2024-08-29 19:45:11 +02:00
2024-04-30 12:42:10 +02:00
$mouvP = new MouvementStock ( $db );
2024-08-29 19:45:11 +02:00
$mouvP -> setOrigin ( $invoice -> element , $invoice -> id );
2024-04-30 12:42:10 +02:00
$res = $mouvP -> livraison ( $user , $line -> fk_product , $warehouseid , $line -> qty , $line -> price , $labeltakeposmovement , '' , '' , '' , $prod_batch -> batch , $prod_batch -> id , $inventorycode );
if ( $res < 0 ) {
2024-08-29 21:48:54 +02:00
dol_htmloutput_errors ( $mouvP -> error , $mouvP -> errors , 1 );
2024-04-30 12:42:10 +02:00
$error ++ ;
}
} else {
$mouvP = new MouvementStock ( $db );
2024-08-29 19:45:11 +02:00
$mouvP -> setOrigin ( $invoice -> element , $invoice -> id );
2024-04-30 12:42:10 +02:00
$res = $mouvP -> livraison ( $user , $line -> fk_product , $warehouseid , $line -> qty , $line -> price , $labeltakeposmovement , '' , '' , '' , '' , 0 , $inventorycode );
if ( $res < 0 ) {
2024-08-29 21:48:54 +02:00
dol_htmloutput_errors ( $mouvP -> error , $mouvP -> errors , 1 );
2024-04-30 12:42:10 +02:00
$error ++ ;
}
}
2023-11-11 12:23:12 +01:00
}
}
}
2024-04-30 12:42:10 +02:00
if ( ! $error && $res >= 0 ) {
$db -> commit ();
} else {
$db -> rollback ();
}
2020-09-07 10:18:17 +02:00
}
2025-02-18 21:48:21 +01:00
$creditnote = null ;
2023-02-14 22:56:12 +01:00
if ( $action == 'creditnote' && $user -> hasRight ( 'facture' , 'creer' )) {
2024-04-30 12:42:10 +02:00
$db -> begin ();
2022-05-03 09:35:06 +02:00
$creditnote = new Facture ( $db );
$creditnote -> socid = $invoice -> socid ;
$creditnote -> date = dol_now ();
$creditnote -> module_source = 'takepos' ;
$creditnote -> pos_source = isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' ;
$creditnote -> type = Facture :: TYPE_CREDIT_NOTE ;
$creditnote -> fk_facture_source = $placeid ;
2023-10-20 10:47:08 +02:00
//$creditnote->remise_absolue = $invoice->remise_absolue;
//$creditnote->remise_percent = $invoice->remise_percent;
2022-05-03 09:35:06 +02:00
$creditnote -> create ( $user );
2024-08-14 01:24:55 +02:00
$fk_parent_line = 0 ; // Initialise
2022-05-03 09:35:06 +02:00
foreach ( $invoice -> lines as $line ) {
// Reset fk_parent_line for no child products and special product
if (( $line -> product_type != 9 && empty ( $line -> fk_parent_line )) || $line -> product_type == 9 ) {
$fk_parent_line = 0 ;
}
2023-03-03 12:08:12 +01:00
if ( getDolGlobalInt ( 'INVOICE_USE_SITUATION' )) {
if ( ! empty ( $invoice -> situation_counter )) {
$source_fk_prev_id = $line -> fk_prev_id ; // temporary storing situation invoice fk_prev_id
$line -> fk_prev_id = $line -> id ; // The new line of the new credit note we are creating must be linked to the situation invoice line it is created from
if ( ! empty ( $invoice -> tab_previous_situation_invoice )) {
// search the last standard invoice in cycle and the possible credit note between this last and invoice
// TODO Move this out of loop of $invoice->lines
$tab_jumped_credit_notes = array ();
$lineIndex = count ( $invoice -> tab_previous_situation_invoice ) - 1 ;
$searchPreviousInvoice = true ;
while ( $searchPreviousInvoice ) {
if ( $invoice -> tab_previous_situation_invoice [ $lineIndex ] -> situation_cycle_ref || $lineIndex < 1 ) {
$searchPreviousInvoice = false ; // find, exit;
break ;
} else {
if ( $invoice -> tab_previous_situation_invoice [ $lineIndex ] -> type == Facture :: TYPE_CREDIT_NOTE ) {
$tab_jumped_credit_notes [ $lineIndex ] = $invoice -> tab_previous_situation_invoice [ $lineIndex ] -> id ;
}
$lineIndex -- ; // go to previous invoice in cycle
2022-05-03 09:35:06 +02:00
}
2020-10-25 20:03:25 +01:00
}
2023-03-03 12:08:12 +01:00
$maxPrevSituationPercent = 0 ;
foreach ( $invoice -> tab_previous_situation_invoice [ $lineIndex ] -> lines as $prevLine ) {
if ( $prevLine -> id == $source_fk_prev_id ) {
$maxPrevSituationPercent = max ( $maxPrevSituationPercent , $prevLine -> situation_percent );
//$line->subprice = $line->subprice - $prevLine->subprice;
2024-08-07 02:53:45 +02:00
$line -> total_ht -= $prevLine -> total_ht ;
$line -> total_tva -= $prevLine -> total_tva ;
$line -> total_ttc -= $prevLine -> total_ttc ;
$line -> total_localtax1 -= $prevLine -> total_localtax1 ;
$line -> total_localtax2 -= $prevLine -> total_localtax2 ;
$line -> multicurrency_subprice -= $prevLine -> multicurrency_subprice ;
$line -> multicurrency_total_ht -= $prevLine -> multicurrency_total_ht ;
$line -> multicurrency_total_tva -= $prevLine -> multicurrency_total_tva ;
$line -> multicurrency_total_ttc -= $prevLine -> multicurrency_total_ttc ;
2023-03-03 12:08:12 +01:00
}
2022-05-03 09:35:06 +02:00
}
2023-03-03 12:08:12 +01:00
// prorata
$line -> situation_percent = $maxPrevSituationPercent - $line -> situation_percent ;
//print 'New line based on invoice id '.$invoice->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>';
// If there is some credit note between last situation invoice and invoice used for credit note generation (note: credit notes are stored as delta)
$maxPrevSituationPercent = 0 ;
foreach ( $tab_jumped_credit_notes as $index => $creditnoteid ) {
foreach ( $invoice -> tab_previous_situation_invoice [ $index ] -> lines as $prevLine ) {
if ( $prevLine -> fk_prev_id == $source_fk_prev_id ) {
$maxPrevSituationPercent = $prevLine -> situation_percent ;
$line -> total_ht -= $prevLine -> total_ht ;
$line -> total_tva -= $prevLine -> total_tva ;
$line -> total_ttc -= $prevLine -> total_ttc ;
$line -> total_localtax1 -= $prevLine -> total_localtax1 ;
$line -> total_localtax2 -= $prevLine -> total_localtax2 ;
$line -> multicurrency_subprice -= $prevLine -> multicurrency_subprice ;
$line -> multicurrency_total_ht -= $prevLine -> multicurrency_total_ht ;
$line -> multicurrency_total_tva -= $prevLine -> multicurrency_total_tva ;
$line -> multicurrency_total_ttc -= $prevLine -> multicurrency_total_ttc ;
}
2022-05-03 09:35:06 +02:00
}
2020-10-25 20:03:25 +01:00
}
2023-03-03 12:08:12 +01:00
// prorata
$line -> situation_percent += $maxPrevSituationPercent ;
2020-10-25 20:03:25 +01:00
2023-03-03 12:08:12 +01:00
//print 'New line based on invoice id '.$invoice->tab_previous_situation_invoice[$lineIndex]->id.' fk_prev_id='.$source_fk_prev_id.' will be fk_prev_id='.$line->fk_prev_id.' '.$line->total_ht.' '.$line->situation_percent.'<br>';
}
2022-05-03 09:35:06 +02:00
}
2020-10-25 20:03:25 +01:00
}
2024-08-29 21:48:54 +02:00
// We update field for credit notes
2022-05-03 09:35:06 +02:00
$line -> fk_facture = $creditnote -> id ;
$line -> fk_parent_line = $fk_parent_line ;
2020-10-25 20:03:25 +01:00
2022-05-03 09:35:06 +02:00
$line -> subprice = - $line -> subprice ; // invert price for object
2024-03-12 22:24:31 +01:00
// $line->pa_ht = $line->pa_ht; // we chose to have the buy/cost price always positive, so no inversion of the sign here
2022-05-03 09:35:06 +02:00
$line -> total_ht = - $line -> total_ht ;
$line -> total_tva = - $line -> total_tva ;
$line -> total_ttc = - $line -> total_ttc ;
$line -> total_localtax1 = - $line -> total_localtax1 ;
$line -> total_localtax2 = - $line -> total_localtax2 ;
2020-10-25 20:03:25 +01:00
2022-05-03 09:35:06 +02:00
$line -> multicurrency_subprice = - $line -> multicurrency_subprice ;
$line -> multicurrency_total_ht = - $line -> multicurrency_total_ht ;
$line -> multicurrency_total_tva = - $line -> multicurrency_total_tva ;
$line -> multicurrency_total_ttc = - $line -> multicurrency_total_ttc ;
2020-10-25 20:03:25 +01:00
2024-01-12 17:18:52 +01:00
$result = $line -> insert ( 0 , 1 ); // When creating credit note with same lines than source, we must ignore error if discount already linked
2020-10-25 20:03:25 +01:00
2022-05-03 09:35:06 +02:00
$creditnote -> lines [] = $line ; // insert new line in current object
2020-10-25 20:03:25 +01:00
2022-05-03 09:35:06 +02:00
// Defined the new fk_parent_line
if ( $result > 0 && $line -> product_type == 9 ) {
$fk_parent_line = $result ;
}
}
$creditnote -> update_price ( 1 );
2024-08-29 21:48:54 +02:00
// The credit note is create here. We must now validate it.
2023-10-09 15:44:57 +02:00
$constantforkey = 'CASHDESK_NO_DECREASE_STOCK' . ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' );
2024-08-29 21:03:53 +02:00
$allowstockchange = getDolGlobalString ( $constantforkey ) != " 1 " ;
2024-08-29 21:48:54 +02:00
if ( isModEnabled ( 'stock' ) && ! isModEnabled ( 'productbatch' ) && $allowstockchange ) {
2024-08-29 19:45:11 +02:00
// If module stock is enabled and we do not setup takepo to disable stock decrease
2024-08-29 21:48:54 +02:00
// The case for isModEnabled('productbatch') is processed few lines later.
2024-01-05 04:18:53 +01:00
$savconst = getDolGlobalString ( 'STOCK_CALCULATE_ON_BILL' );
2024-08-29 19:45:11 +02:00
$conf -> global -> STOCK_CALCULATE_ON_BILL = 1 ; // We force setup to have update of stock on invoice validation/unvalidation
2024-08-29 21:03:53 +02:00
2023-10-09 15:44:57 +02:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' );
2024-08-29 19:45:11 +02:00
dol_syslog ( " Validate invoice with stock change into warehouse defined into constant " . $constantforkey . " = " . getDolGlobalString ( $constantforkey ) . " or warehouseid= " . $warehouseid . " if defined. " );
2024-08-29 21:03:53 +02:00
2024-08-29 21:48:54 +02:00
// Validate invoice with stock change into warehouse getDolGlobalInt($constantforkey)
// Label of stock movement will be the same as when we validate invoice "Invoice XXXX validated"
$batch_rule = 0 ; // Module productbatch is disabled here, so no need for a batch_rule.
2025-02-18 21:48:21 +01:00
$res = $creditnote -> validate ( $user , '' , getDolGlobalInt ( $constantforkey ), 0 , $batch_rule );
2024-08-29 21:03:53 +02:00
if ( $res < 0 ) {
$error ++ ;
dol_htmloutput_errors ( $creditnote -> error , $creditnote -> errors , 1 );
}
// Restore setup
2022-05-03 09:35:06 +02:00
$conf -> global -> STOCK_CALCULATE_ON_BILL = $savconst ;
} else {
$res = $creditnote -> validate ( $user );
2020-10-25 20:03:25 +01:00
}
2024-04-30 12:42:10 +02:00
2024-08-29 21:48:54 +02:00
// Update stock for batch products
if ( ! $error && $res >= 0 ) {
if ( isModEnabled ( 'stock' ) && isModEnabled ( 'productbatch' ) && $allowstockchange ) {
// Update stocks
dol_syslog ( " Now we record the stock movement for each qualified line " );
// The case !isModEnabled('productbatch') was processed few lines before.
require_once DOL_DOCUMENT_ROOT . " /product/stock/class/mouvementstock.class.php " ;
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
$inventorycode = dol_print_date ( dol_now (), 'dayhourlog' );
// Label of stock movement will be "TakePOS - Invoice XXXX"
$labeltakeposmovement = 'TakePOS - ' . $langs -> trans ( " CreditNote " ) . ' ' . $creditnote -> ref ;
foreach ( $creditnote -> lines as $line ) {
// Use the warehouse id defined on invoice line else in the setup
$warehouseid = ( $line -> fk_warehouse ? $line -> fk_warehouse : getDolGlobalInt ( $constantforkey ));
//var_dump('fk_product='.$line->fk_product.' batch='.$line->batch.' warehouse='.$line->fk_warehouse.' qty='.$line->qty);exit;
if ( $line -> batch != '' && $warehouseid > 0 ) {
//$prod_batch = new Productbatch($db);
//$prod_batch->find(0, '', '', $line->batch, $warehouseid);
$mouvP = new MouvementStock ( $db );
$mouvP -> setOrigin ( $creditnote -> element , $creditnote -> id );
$res = $mouvP -> reception ( $user , $line -> fk_product , $warehouseid , $line -> qty , $line -> price , $labeltakeposmovement , '' , '' , $line -> batch , '' , 0 , $inventorycode );
if ( $res < 0 ) {
dol_htmloutput_errors ( $mouvP -> error , $mouvP -> errors , 1 );
$error ++ ;
}
} else {
$mouvP = new MouvementStock ( $db );
$mouvP -> setOrigin ( $creditnote -> element , $creditnote -> id );
$res = $mouvP -> reception ( $user , $line -> fk_product , $warehouseid , $line -> qty , $line -> price , $labeltakeposmovement , '' , '' , '' , '' , 0 , $inventorycode );
if ( $res < 0 ) {
dol_htmloutput_errors ( $mouvP -> error , $mouvP -> errors , 1 );
$error ++ ;
}
}
}
}
}
2024-04-30 12:42:10 +02:00
if ( ! $error && $res >= 0 ) {
$db -> commit ();
} else {
2024-08-29 21:03:53 +02:00
$creditnote -> id = $placeid ; // Creation has failed, we reset to ID of source invoice so we go back to this one in action=history
2024-04-30 12:42:10 +02:00
$db -> rollback ();
}
2020-10-25 20:03:25 +01:00
}
2019-04-28 18:12:33 +02:00
2024-01-07 13:38:13 +01:00
if (( $action == 'history' || $action == 'creditnote' ) && $user -> hasRight ( 'takepos' , 'run' )) {
2025-02-18 21:48:21 +01:00
if ( $action == 'creditnote' && $creditnote !== null && $creditnote -> id > 0 ) { // Test on permission already done
2022-05-03 09:35:06 +02:00
$placeid = $creditnote -> id ;
} else {
2024-02-22 19:18:00 +01:00
$placeid = GETPOSTINT ( 'placeid' );
2019-08-01 12:23:02 +02:00
}
2024-08-29 21:03:53 +02:00
2022-05-03 09:35:06 +02:00
$invoice = new Facture ( $db );
$invoice -> fetch ( $placeid );
2019-08-01 12:23:02 +02:00
}
2018-09-28 13:31:41 +02:00
2023-07-30 14:30:47 +02:00
// If we add a line and no invoice yet, we create the invoice
2024-01-07 16:31:44 +01:00
if (( $action == " addline " || $action == " freezone " ) && $placeid == 0 && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
2024-01-25 12:22:09 +01:00
$invoice -> socid = getDolGlobalInt ( $constforcompanyid );
2024-07-01 02:46:48 +02:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php' ;
$invoice -> date = dol_get_first_hour ( dol_now ( 'tzuserrel' )); // Invoice::create() needs a date with no hours
2022-05-03 09:35:06 +02:00
$invoice -> module_source = 'takepos' ;
$invoice -> pos_source = isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' ;
$invoice -> entity = ! empty ( $_SESSION [ " takeposinvoiceentity " ]) ? $_SESSION [ " takeposinvoiceentity " ] : $conf -> entity ;
if ( $invoice -> socid <= 0 ) {
$langs -> load ( 'errors' );
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $langs -> trans ( " ErrorModuleSetupNotComplete " , " TakePos " ), [], 1 );
2022-05-03 09:35:06 +02:00
} else {
2024-04-30 12:42:10 +02:00
$db -> begin ();
2023-07-30 14:30:47 +02:00
// Create invoice
2022-05-03 09:35:06 +02:00
$placeid = $invoice -> create ( $user );
if ( $placeid < 0 ) {
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
2021-02-26 21:17:52 +01:00
}
2024-11-22 12:07:48 +01:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facture " ;
$sql .= " SET ref='(PROV-POS " . $_SESSION [ " takeposterminal " ] . " - " . $place . " )' " ;
$sql .= " WHERE rowid = " . (( int ) $placeid );
2024-04-30 12:42:10 +02:00
$resql = $db -> query ( $sql );
if ( ! $resql ) {
$error ++ ;
}
if ( ! $error ) {
$db -> commit ();
} else {
$db -> rollback ();
}
2019-12-08 23:16:49 +01:00
}
}
2025-02-18 21:48:21 +01:00
$tva_npr = 0 ;
2024-03-22 02:11:58 +01:00
// If we add a line by click on product (invoice exists here because it was created juste before if it didn't exists)
2024-01-07 16:31:44 +01:00
if ( $action == " addline " && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
2022-05-03 09:35:06 +02:00
$prod = new Product ( $db );
$prod -> fetch ( $idproduct );
$customer = new Societe ( $db );
$customer -> fetch ( $invoice -> socid );
$datapriceofproduct = $prod -> getSellPrice ( $mysoc , $customer , 0 );
2024-11-19 13:21:31 +01:00
$qty = GETPOSTISSET ( 'qty' ) ? GETPOSTFLOAT ( 'qty' ) : 1 ;
2022-05-03 09:35:06 +02:00
$price = $datapriceofproduct [ 'pu_ht' ];
$price_ttc = $datapriceofproduct [ 'pu_ttc' ];
//$price_min = $datapriceofproduct['price_min'];
2023-08-23 23:41:16 +02:00
$price_base_type = empty ( $datapriceofproduct [ 'price_base_type' ]) ? 'HT' : $datapriceofproduct [ 'price_base_type' ];
2022-05-03 09:35:06 +02:00
$tva_tx = $datapriceofproduct [ 'tva_tx' ];
2025-02-18 21:48:21 +01:00
$tva_npr = ( int ) $datapriceofproduct [ 'tva_npr' ];
2022-05-03 09:35:06 +02:00
// Local Taxes
$localtax1_tx = get_localtax ( $tva_tx , 1 , $customer , $mysoc , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $customer , $mysoc , $tva_npr );
2024-02-10 12:02:09 +01:00
2023-11-11 12:23:12 +01:00
if ( isModEnabled ( 'productbatch' ) && isModEnabled ( 'stock' )) {
$batch = GETPOST ( 'batch' , 'alpha' );
2024-08-29 19:45:11 +02:00
if ( ! empty ( $batch )) { // We have just clicked on a batch number, we will execute action=setbatch later...
2024-03-07 20:16:48 +01:00
$action = " setbatch " ;
2024-04-30 12:42:10 +02:00
} elseif ( $prod -> status_batch > 0 ) {
// If product need a lot/serial, we show the list of lot/serial available for the product...
2024-02-10 12:02:09 +01:00
// Set nb of suggested with nb of batch into the warehouse of the terminal
2023-12-23 19:47:10 +01:00
$nbofsuggested = 0 ;
2023-11-11 12:23:12 +01:00
$prod -> load_stock ( 'warehouseopen' );
2024-04-30 12:42:10 +02:00
2023-11-11 12:23:12 +01:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
2024-04-30 11:01:37 +02:00
$warehouseid = getDolGlobalInt ( $constantforkey );
2024-04-30 12:42:10 +02:00
//var_dump($prod->stock_warehouse);
foreach ( $prod -> stock_warehouse as $tmpwarehouseid => $tmpval ) {
if ( getDolGlobalInt ( $constantforkey ) && $tmpwarehouseid != getDolGlobalInt ( $constantforkey )) {
2024-08-29 19:45:11 +02:00
// Product to select is not on the warehouse configured for terminal, so we ignore this warehouse
2024-04-30 12:42:10 +02:00
continue ;
}
if ( ! empty ( $prod -> stock_warehouse [ $tmpwarehouseid ]) && is_array ( $prod -> stock_warehouse [ $tmpwarehouseid ] -> detail_batch )) {
if ( is_object ( $prod -> stock_warehouse [ $tmpwarehouseid ]) && count ( $prod -> stock_warehouse [ $tmpwarehouseid ] -> detail_batch )) {
foreach ( $prod -> stock_warehouse [ $tmpwarehouseid ] -> detail_batch as $dbatch ) {
$nbofsuggested ++ ;
}
2023-12-04 13:53:48 +01:00
}
2023-11-11 12:23:12 +01:00
}
}
2024-04-30 13:03:17 +02:00
//var_dump($prod->stock_warehouse);
2023-11-11 12:23:12 +01:00
2024-04-30 11:01:37 +02:00
echo " <script> \n " ;
echo " function addbatch(batch, warehouseid) { \n " ;
echo " console.log('We add batch '+batch+' from warehouse id '+warehouseid); \n " ;
2024-08-29 19:45:11 +02:00
echo '$("#poslines").load("' . DOL_URL_ROOT . '/takepos/invoice.php?action=addline&batch="+encodeURI(batch)+"&warehouseid="+warehouseid+"&place=' . $place . '&idproduct=' . $idproduct . '&token=' . newToken () . '", function() {});' . " \n " ;
2024-04-30 11:01:37 +02:00
echo " } \n " ;
echo " </script> \n " ;
2023-11-11 12:23:12 +01:00
2024-04-30 12:42:10 +02:00
$suggestednb = 1 ;
echo " <center> " . $langs -> trans ( " SearchIntoBatch " ) . " : <b> $nbofsuggested </b></center><br><table> " ;
foreach ( $prod -> stock_warehouse as $tmpwarehouseid => $tmpval ) {
if ( getDolGlobalInt ( $constantforkey ) && $tmpwarehouseid != getDolGlobalInt ( $constantforkey )) {
2024-05-03 18:01:17 +02:00
// Not on the forced warehouse, so we ignore this warehouse
2024-04-30 12:42:10 +02:00
continue ;
}
if ( ! empty ( $prod -> stock_warehouse [ $tmpwarehouseid ]) && is_array ( $prod -> stock_warehouse [ $tmpwarehouseid ] -> detail_batch )) {
foreach ( $prod -> stock_warehouse [ $tmpwarehouseid ] -> detail_batch as $dbatch ) { // $dbatch is instance of Productbatch
$batchStock = + $dbatch -> qty ; // To get a numeric
$quantityToBeDelivered = 1 ;
$deliverableQty = min ( $quantityToBeDelivered , $batchStock );
print '<tr>' ;
print '<!-- subj=' . $suggestednb . '/' . $nbofsuggested . ' -->' ;
2024-08-29 19:45:11 +02:00
print '<!-- Show details of lot/serial in warehouseid=' . $tmpwarehouseid . ' -->' ;
2024-04-30 12:42:10 +02:00
print '<td class="left">' ;
$detail = '' ;
$detail .= '<span class="opacitymedium">' . $langs -> trans ( " LotSerial " ) . ':</span> ' . $dbatch -> batch ;
2025-02-18 21:48:21 +01:00
//if (!getDolGlobalString('PRODUCT_DISABLE_SELLBY')) {
//$detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day");
//}
//if (!getDolGlobalString('PRODUCT_DISABLE_EATBY')) {
//$detail .= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby, "day");
//}
2024-04-30 12:42:10 +02:00
$detail .= '</td><td>' ;
$detail .= '<span class="opacitymedium">' . $langs -> trans ( " Qty " ) . ':</span> ' . $dbatch -> qty ;
$detail .= '</td><td>' ;
$detail .= ' <button class="marginleftonly" onclick="addbatch(\'' . dol_escape_js ( $dbatch -> batch ) . '\', ' . $tmpwarehouseid . ')">' . $langs -> trans ( " Select " ) . " </button> " ;
$detail .= '<br>' ;
print $detail ;
$quantityToBeDelivered -= $deliverableQty ;
if ( $quantityToBeDelivered < 0 ) {
$quantityToBeDelivered = 0 ;
}
$suggestednb ++ ;
print '</td></tr>' ;
2023-11-11 12:23:12 +01:00
}
}
}
2024-04-30 12:42:10 +02:00
print " </table> " ;
print '</body></html>' ;
exit ;
2023-11-11 12:23:12 +01:00
}
}
2024-02-10 12:02:09 +01:00
2023-10-09 14:14:37 +02:00
if ( getDolGlobalString ( 'TAKEPOS_SUPPLEMENTS' )) {
2022-05-03 09:35:06 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$cat = new Categorie ( $db );
$categories = $cat -> containing ( $idproduct , 'product' );
2023-10-09 14:14:37 +02:00
$found = ( array_search ( getDolGlobalInt ( 'TAKEPOS_SUPPLEMENTS_CATEGORY' ), array_column ( $categories , 'id' )));
2022-05-03 09:35:06 +02:00
if ( $found !== false ) { // If this product is a supplement
2023-10-09 14:14:37 +02:00
$sql = " SELECT fk_parent_line FROM " . MAIN_DB_PREFIX . " facturedet where rowid = " . (( int ) $selectedline );
2022-05-03 09:35:06 +02:00
$resql = $db -> query ( $sql );
$row = $db -> fetch_array ( $resql );
if ( $row [ 0 ] == null ) {
$parent_line = $selectedline ;
2020-03-12 11:00:17 +01:00
} else {
2022-05-03 09:35:06 +02:00
$parent_line = $row [ 0 ]; //If the parent line is already a supplement, add the supplement to the main product
2020-03-12 11:00:17 +01:00
}
}
}
2022-05-03 09:35:06 +02:00
2023-10-12 20:24:55 +02:00
$err = 0 ;
2022-05-03 09:35:06 +02:00
// Group if enabled. Skip group if line already sent to the printer
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'TAKEPOS_GROUP_SAME_PRODUCT' )) {
2022-05-03 09:35:06 +02:00
foreach ( $invoice -> lines as $line ) {
if ( $line -> product_ref == $prod -> ref ) {
2024-03-07 20:16:48 +01:00
if ( $line -> special_code == 4 ) {
2023-12-04 13:53:48 +01:00
continue ;
} // If this line is sended to printer create new line
2023-10-12 20:24:55 +02:00
// check if qty in stock
2023-10-13 15:43:42 +02:00
if ( getDolGlobalString ( 'TAKEPOS_QTY_IN_STOCK' ) && (( $line -> qty + $qty ) > $prod -> stock_reel )) {
2024-01-23 23:25:15 +01:00
$invoice -> error = $langs -> trans ( " ErrorStockIsNotEnough " );
2023-10-12 20:24:55 +02:00
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
$err ++ ;
break ;
}
2022-05-03 09:35:06 +02:00
$result = $invoice -> updateline ( $line -> id , $line -> desc , $line -> subprice , $line -> qty + $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 );
if ( $result < 0 ) {
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
} else {
$idoflineadded = $line -> id ;
}
break ;
}
}
}
2023-10-12 20:24:55 +02:00
if ( $idoflineadded <= 0 && empty ( $err )) {
2022-05-03 09:35:06 +02:00
$invoice -> fetch_thirdparty ();
2022-05-06 15:49:44 +02:00
$array_options = array ();
2023-07-10 05:45:45 +02:00
$line = array ( 'description' => $prod -> description , 'price' => $price , 'tva_tx' => $tva_tx , 'localtax1_tx' => $localtax1_tx , 'localtax2_tx' => $localtax2_tx , 'remise_percent' => $customer -> remise_percent , 'price_ttc' => $price_ttc , 'array_options' => $array_options );
2022-07-26 15:38:50 +02:00
2022-08-11 16:01:29 +02:00
/* setup of margin calculation */
2024-11-22 12:29:00 +01:00
if ( getDolGlobalString ( 'MARGIN_TYPE' )) {
2023-10-08 23:19:49 +02:00
if ( getDolGlobalString ( 'MARGIN_TYPE' ) == 'pmp' && ! empty ( $prod -> pmp )) {
2022-08-11 16:01:29 +02:00
$line [ 'fk_fournprice' ] = null ;
$line [ 'pa_ht' ] = $prod -> pmp ;
2023-10-08 23:19:49 +02:00
} elseif ( getDolGlobalString ( 'MARGIN_TYPE' ) == 'costprice' && ! empty ( $prod -> cost_price )) {
2022-08-11 16:01:29 +02:00
$line [ 'fk_fournprice' ] = null ;
$line [ 'pa_ht' ] = $prod -> cost_price ;
} else {
// default is fournprice
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php' ;
$pf = new ProductFournisseur ( $db );
if ( $pf -> find_min_price_product_fournisseur ( $idproduct , $qty ) > 0 ) {
$line [ 'fk_fournprice' ] = $pf -> product_fourn_price_id ;
$line [ 'pa_ht' ] = $pf -> fourn_unitprice_with_discount ;
2023-12-04 13:53:48 +01:00
if ( getDolGlobalString ( 'PRODUCT_CHARGES' ) && $pf -> fourn_charges > 0 ) {
2024-10-03 19:40:34 +02:00
$line [ 'pa_ht' ] += ( float ) $pf -> fourn_charges / $pf -> fourn_qty ;
2023-12-04 13:53:48 +01:00
}
2022-08-11 16:01:29 +02:00
}
}
}
2022-05-06 15:49:44 +02:00
// complete line by hook
2022-07-26 15:38:50 +02:00
$parameters = array ( 'prod' => $prod , 'line' => $line );
2024-03-07 20:16:48 +01:00
$reshook = $hookmanager -> executeHooks ( 'completeTakePosAddLine' , $parameters , $invoice , $action ); // Note that $action and $line may have been modified by some hooks
2023-12-04 13:53:48 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2022-05-06 15:49:44 +02:00
2022-07-26 15:38:50 +02:00
2022-07-26 15:47:03 +02:00
if ( empty ( $reshook )) {
if ( ! empty ( $hookmanager -> resArray )) {
$line = $hookmanager -> resArray ;
}
2023-10-12 20:24:55 +02:00
// check if qty in stock
2023-10-13 15:43:42 +02:00
if ( getDolGlobalString ( 'TAKEPOS_QTY_IN_STOCK' ) && $qty > $prod -> stock_reel ) {
2024-01-23 23:25:15 +01:00
$invoice -> error = $langs -> trans ( " ErrorStockIsNotEnough " );
2023-10-12 20:24:55 +02:00
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
$err ++ ;
}
if ( empty ( $err )) {
2025-02-18 21:48:21 +01:00
$idoflineadded = $invoice -> addline ( $line [ 'description' ], $line [ 'price' ], $qty , $line [ 'tva_tx' ], $line [ 'localtax1_tx' ], $line [ 'localtax2_tx' ], $idproduct , ( float ) $line [ 'remise_percent' ], '' , 0 , 0 , 0 , 0 , $price_base_type , $line [ 'price_ttc' ], $prod -> type , - 1 , 0 , '' , 0 , ( empty ( $parent_line ) ? '' : $parent_line ), ( empty ( $line [ 'fk_fournprice' ]) ? 0 : $line [ 'fk_fournprice' ]), ( empty ( $line [ 'pa_ht' ]) ? '' : $line [ 'pa_ht' ]), '' , $line [ 'array_options' ], 100 , 0 , null , 0 );
2023-10-12 20:24:55 +02:00
}
2022-07-26 15:47:03 +02:00
}
2022-05-06 15:49:44 +02:00
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'TAKEPOS_CUSTOMER_DISPLAY' )) {
2022-05-03 09:35:06 +02:00
$CUSTOMER_DISPLAY_line1 = $prod -> label ;
$CUSTOMER_DISPLAY_line2 = price ( $price_ttc );
}
2021-08-08 19:14:28 +02:00
}
2020-01-01 22:37:13 +01:00
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
}
2018-09-28 13:31:41 +02:00
2025-02-18 21:48:21 +01:00
// If we add a line by submitting freezone form (invoice exists here because it was created just before if it didn't exist)
2024-01-07 16:31:44 +01:00
if ( $action == " freezone " && $user -> hasRight ( 'takepos' , 'run' )) {
2022-05-03 09:35:06 +02:00
$customer = new Societe ( $db );
$customer -> fetch ( $invoice -> socid );
2020-01-01 21:54:47 +01:00
2022-05-03 09:35:06 +02:00
$tva_tx = GETPOST ( 'tva_tx' , 'alpha' );
if ( $tva_tx != '' ) {
if ( ! preg_match ( '/\((.*)\)/' , $tva_tx )) {
$tva_tx = price2num ( $tva_tx );
}
} else {
$tva_tx = get_default_tva ( $mysoc , $customer );
2021-02-10 01:10:31 +01:00
}
2020-01-01 21:54:47 +01:00
2022-05-03 09:35:06 +02:00
// Local Taxes
$localtax1_tx = get_localtax ( $tva_tx , 1 , $customer , $mysoc , $tva_npr );
$localtax2_tx = get_localtax ( $tva_tx , 2 , $customer , $mysoc , $tva_npr );
2018-09-28 13:31:41 +02:00
2025-02-18 21:48:21 +01:00
$res = $invoice -> addline ( $desc , $number , 1 , $tva_tx , $localtax1_tx , $localtax2_tx , 0 , 0 , '' , 0 , 0 , 0 , 0 , getDolGlobalInt ( 'TAKEPOS_DISCOUNT_TTC' ) ? ( $number >= 0 ? 'HT' : 'TTC' ) : ( getDolGlobalInt ( 'TAKEPOS_CHANGE_PRICE_HT' ) ? 'HT' : 'TTC' ), $number , 0 , - 1 , 0 , '' , 0 , 0 , 0 , 0 , '' , array (), 100 , 0 , null , 0 );
2024-03-22 02:11:58 +01:00
if ( $res < 0 ) {
dol_htmloutput_errors ( $invoice -> error , $invoice -> errors , 1 );
}
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
2020-09-08 21:27:28 +02:00
}
2019-03-03 12:50:36 +01:00
2024-01-07 16:31:44 +01:00
if ( $action == " addnote " && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
2022-05-03 09:35:06 +02:00
$desc = GETPOST ( 'addnote' , 'alpha' );
2024-03-07 20:16:48 +01:00
if ( $idline == 0 ) {
2022-05-03 09:35:06 +02:00
$invoice -> update_note ( $desc , '_public' );
2023-12-04 13:53:48 +01:00
} else {
foreach ( $invoice -> lines as $line ) {
if ( $line -> id == $idline ) {
$result = $invoice -> updateline ( $line -> id , $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 );
}
2022-05-03 09:35:06 +02:00
}
}
2020-09-08 21:27:28 +02:00
$invoice -> fetch ( $placeid );
}
2022-05-03 09:35:06 +02:00
2024-01-07 16:31:44 +01:00
if ( $action == " deleteline " && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
/*
$permissiontoupdateline = ( $user -> hasRight ( 'takepos' , 'editlines' ) && ( $user -> hasRight ( 'takepos' , 'editorderedlines' ) || $line -> special_code != " 4 " ));
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
if ( $invoice -> status == $invoice :: STATUS_DRAFT && $invoice -> pos_source && $invoice -> module_source == 'takepos' ) {
$permissiontoupdateline = true ;
// TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
2024-11-22 12:07:48 +01:00
// TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
2024-01-07 16:31:44 +01:00
}
} */
if ( $idline > 0 && $placeid > 0 ) { // If invoice exists and line selected. To avoid errors if deleted from another device or no line selected.
2024-02-02 23:46:12 +01:00
$invoice -> deleteLine ( $idline );
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
} elseif ( $placeid > 0 ) { // If invoice exists but no line selected, proceed to delete last line.
$sql = " SELECT rowid FROM " . MAIN_DB_PREFIX . " facturedet where fk_facture = " . (( int ) $placeid ) . " ORDER BY rowid DESC " ;
$resql = $db -> query ( $sql );
$row = $db -> fetch_array ( $resql );
$deletelineid = $row [ 0 ];
2024-02-02 23:46:12 +01:00
$invoice -> deleteLine ( $deletelineid );
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
}
2024-01-07 16:31:44 +01:00
2022-05-03 09:35:06 +02:00
if ( count ( $invoice -> lines ) == 0 ) {
$invoice -> delete ( $user );
2024-04-30 12:42:10 +02:00
2024-01-07 16:31:44 +01:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
header ( " Location: " . DOL_URL_ROOT . " /takepos/public/auto_order.php " );
} else {
header ( " Location: " . DOL_URL_ROOT . " /takepos/invoice.php " );
}
2022-05-03 09:35:06 +02:00
exit ;
}
2020-10-04 15:54:23 +02:00
}
2018-09-28 13:31:41 +02:00
2022-05-03 09:35:06 +02:00
// Action to delete or discard an invoice
2024-01-07 16:31:44 +01:00
if ( $action == " delete " && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
2024-11-22 12:07:48 +01: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 beginning of page works.
2022-05-03 09:35:06 +02:00
if ( $placeid > 0 ) {
$result = $invoice -> fetch ( $placeid );
2019-08-27 15:39:35 +02:00
2024-11-22 12:07:48 +01:00
if ( $result > 0 && $invoice -> status == Facture :: STATUS_DRAFT ) {
2022-05-03 09:35:06 +02:00
$db -> begin ();
2019-08-27 15:42:35 +02:00
2022-05-03 09:35:06 +02:00
// We delete the lines
$resdeletelines = 1 ;
foreach ( $invoice -> lines as $line ) {
2024-03-07 20:16:48 +01:00
// @phan-suppress-next-line PhanPluginSuspiciousParamPosition
2024-02-02 23:46:12 +01:00
$tmpres = $invoice -> deleteLine ( $line -> id );
2022-05-03 09:35:06 +02:00
if ( $tmpres < 0 ) {
$resdeletelines = 0 ;
break ;
}
2020-11-30 15:39:35 +01:00
}
2020-11-30 11:32:58 +01:00
2022-05-03 09:35:06 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facture " ;
$varforconst = 'CASHDESK_ID_THIRDPARTY' . $_SESSION [ " takeposterminal " ];
2023-10-09 15:44:57 +02:00
$sql .= " SET fk_soc = " . (( int ) getDolGlobalString ( $varforconst )) . " , " ;
2022-05-03 09:35:06 +02:00
$sql .= " datec = ' " . $db -> idate ( dol_now ()) . " ' " ;
2024-03-31 13:56:44 +02:00
$sql .= " WHERE entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
$sql .= " AND ref = '(PROV-POS " . $db -> escape ( $_SESSION [ " takeposterminal " ] . " - " . $place ) . " )' " ;
2022-05-03 09:35:06 +02:00
$resql1 = $db -> query ( $sql );
2019-08-27 15:42:35 +02:00
2022-05-03 09:35:06 +02:00
if ( $resdeletelines && $resql1 ) {
$db -> commit ();
} else {
$db -> rollback ();
}
2019-04-02 17:36:27 +02:00
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
}
2020-09-07 10:18:17 +02:00
}
}
2019-04-02 17:36:27 +02:00
2024-01-07 13:38:13 +01:00
if ( $action == " updateqty " ) { // Test on permission is done later
2022-05-03 09:35:06 +02:00
foreach ( $invoice -> lines as $line ) {
if ( $line -> id == $idline ) {
2024-01-07 13:38:13 +01:00
$permissiontoupdateline = ( $user -> hasRight ( 'takepos' , 'editlines' ) && ( $user -> hasRight ( 'takepos' , 'editorderedlines' ) || $line -> special_code != " 4 " ));
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
if ( $invoice -> status == $invoice :: STATUS_DRAFT && $invoice -> pos_source && $invoice -> module_source == 'takepos' ) {
$permissiontoupdateline = true ;
// TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
2024-11-22 12:07:48 +01:00
// TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
2024-01-07 13:38:13 +01:00
}
}
if ( ! $permissiontoupdateline ) {
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $langs -> trans ( " NotEnoughPermissions " , " TakePos " ) . ' - No permission to updateqty' , [], 1 );
2022-05-03 09:35:06 +02:00
} else {
2024-10-08 23:51:51 +02:00
$vatratecode = $line -> tva_tx ;
if ( $line -> vat_src_code ) {
$vatratecode .= ' (' . $line -> vat_src_code . ')' ;
}
$result = $invoice -> updateline ( $line -> id , $line -> desc , $line -> subprice , $number , $line -> remise_percent , $line -> date_start , $line -> date_end , $vatratecode , $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 );
2022-05-03 09:35:06 +02:00
}
2021-07-06 03:53:42 +02:00
}
2020-09-07 10:18:17 +02:00
}
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
2020-09-07 10:18:17 +02:00
}
2018-12-07 17:02:06 +01:00
2024-01-07 13:38:13 +01:00
if ( $action == " updateprice " ) { // Test on permission is done later
2022-05-03 09:35:06 +02:00
$customer = new Societe ( $db );
$customer -> fetch ( $invoice -> socid );
2018-09-28 13:31:41 +02:00
2022-05-03 09:35:06 +02:00
foreach ( $invoice -> lines as $line ) {
if ( $line -> id == $idline ) {
$prod = new Product ( $db );
$prod -> fetch ( $line -> fk_product );
$datapriceofproduct = $prod -> getSellPrice ( $mysoc , $customer , 0 );
$price_min = $datapriceofproduct [ 'price_min' ];
2024-02-09 15:58:49 +01:00
$usercanproductignorepricemin = (( getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) && ! $user -> hasRight ( 'produit' , 'ignore_price_min_advance' )) || ! getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ));
2024-08-07 00:37:46 +02:00
$vatratecleaned = $line -> tva_tx ;
$reg = array ();
if ( preg_match ( '/^(.*)\s*\((.*)\)$/' , ( string ) $line -> tva_tx , $reg )) { // If vat is "xx (yy)"
$vatratecleaned = trim ( $reg [ 1 ]);
//$vatratecode = $reg[2];
}
2024-08-15 16:57:02 +02:00
$pu_ht = price2num (( float ) price2num ( $number , 'MU' ) / ( 1 + (( float ) $vatratecleaned / 100 )), 'MU' );
2024-08-07 00:37:46 +02:00
// Check min price
2024-08-15 16:57:02 +02:00
if ( $usercanproductignorepricemin && ( ! empty ( $price_min ) && (( float ) price2num ( $pu_ht ) * ( 1 - ( float ) price2num ( $line -> remise_percent ) / 100 ) < price2num ( $price_min )))) {
2022-11-02 00:36:08 +01:00
$langs -> load ( " products " );
dol_htmloutput_errors ( $langs -> trans ( " CantBeLessThanMinPrice " , price ( price2num ( $price_min , 'MU' ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency )));
2024-08-07 00:37:46 +02:00
// echo $langs->trans("CantBeLessThanMinPrice");
2021-07-06 03:53:42 +02:00
} else {
2024-01-07 13:38:13 +01:00
$permissiontoupdateline = ( $user -> hasRight ( 'takepos' , 'editlines' ) && ( $user -> hasRight ( 'takepos' , 'editorderedlines' ) || $line -> special_code != " 4 " ));
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
if ( $invoice -> status == $invoice :: STATUS_DRAFT && $invoice -> pos_source && $invoice -> module_source == 'takepos' ) {
$permissiontoupdateline = true ;
// TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
2024-11-22 12:07:48 +01:00
// TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
2024-01-07 13:38:13 +01:00
}
}
2024-10-08 23:51:51 +02:00
$vatratecode = $line -> tva_tx ;
if ( $line -> vat_src_code ) {
$vatratecode .= ' (' . $line -> vat_src_code . ')' ;
}
2024-01-07 13:38:13 +01:00
if ( ! $permissiontoupdateline ) {
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $langs -> trans ( " NotEnoughPermissions " , " TakePos " ) . ' - No permission to updateprice' , [], 1 );
2022-05-03 09:35:06 +02:00
} elseif ( getDolGlobalInt ( 'TAKEPOS_CHANGE_PRICE_HT' ) == 1 ) {
2024-10-08 23:51:51 +02:00
$result = $invoice -> updateline ( $line -> id , $line -> desc , $number , $line -> qty , $line -> remise_percent , $line -> date_start , $line -> date_end , $vatratecode , $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 );
2022-05-03 09:35:06 +02:00
} else {
2024-10-08 23:51:51 +02:00
$result = $invoice -> updateline ( $line -> id , $line -> desc , $number , $line -> qty , $line -> remise_percent , $line -> date_start , $line -> date_end , $vatratecode , $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 );
2022-05-03 09:35:06 +02:00
}
2021-07-06 03:53:42 +02:00
}
2021-02-26 21:17:52 +01:00
}
2020-09-07 10:18:17 +02:00
}
2021-07-06 03:53:42 +02:00
2022-05-03 09:35:06 +02:00
// Reload data
$invoice -> fetch ( $placeid );
}
2018-09-28 13:31:41 +02:00
2024-01-07 13:38:13 +01:00
if ( $action == " updatereduction " ) { // Test on permission is done later
2022-05-03 09:35:06 +02:00
$customer = new Societe ( $db );
$customer -> fetch ( $invoice -> socid );
2021-07-06 03:53:42 +02:00
2022-05-03 09:35:06 +02:00
foreach ( $invoice -> lines as $line ) {
if ( $line -> id == $idline ) {
dol_syslog ( " updatereduction Process line " . $line -> id . ' to apply discount of ' . $number . '%' );
2021-07-06 03:53:42 +02:00
2022-05-03 09:35:06 +02:00
$prod = new Product ( $db );
$prod -> fetch ( $line -> fk_product );
2021-07-06 03:53:42 +02:00
2022-05-03 09:35:06 +02:00
$datapriceofproduct = $prod -> getSellPrice ( $mysoc , $customer , 0 );
$price_min = $datapriceofproduct [ 'price_min' ];
2024-02-09 15:58:49 +01:00
$usercanproductignorepricemin = (( getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ) && ! $user -> hasRight ( 'produit' , 'ignore_price_min_advance' )) || ! getDolGlobalString ( 'MAIN_USE_ADVANCED_PERMS' ));
2021-07-06 03:53:42 +02:00
2022-05-03 09:35:06 +02:00
$pu_ht = price2num ( $line -> subprice / ( 1 + ( $line -> tva_tx / 100 )), 'MU' );
2021-07-06 03:53:42 +02:00
2022-05-03 09:35:06 +02:00
// Check min price
2024-08-15 16:57:02 +02:00
if ( $usercanproductignorepricemin && ( ! empty ( $price_min ) && (( float ) price2num ( $line -> subprice ) * ( 1 - ( float ) price2num ( $number ) / 100 ) < ( float ) price2num ( $price_min )))) {
2022-11-02 00:36:08 +01:00
$langs -> load ( " products " );
dol_htmloutput_errors ( $langs -> trans ( " CantBeLessThanMinPrice " , price ( price2num ( $price_min , 'MU' ), 0 , $langs , 0 , 0 , - 1 , $conf -> currency )));
2021-07-06 03:53:42 +02:00
} else {
2024-01-07 13:38:13 +01:00
$permissiontoupdateline = ( $user -> hasRight ( 'takepos' , 'editlines' ) && ( $user -> hasRight ( 'takepos' , 'editorderedlines' ) || $line -> special_code != " 4 " ));
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
if ( $invoice -> status == $invoice :: STATUS_DRAFT && $invoice -> pos_source && $invoice -> module_source == 'takepos' ) {
$permissiontoupdateline = true ;
// TODO Add also a test on $_SESSION('publicobjectid'] defined at creation of object
2024-11-22 12:07:48 +01:00
// TODO Check also that invoice->ref is (PROV-POS1-2) with 1 = terminal and 2, the table ID
2024-01-07 13:38:13 +01:00
}
}
if ( ! $permissiontoupdateline ) {
2024-09-20 01:46:07 +02:00
dol_htmloutput_errors ( $langs -> trans ( " NotEnoughPermissions " , " TakePos " ), [], 1 );
2022-05-03 09:35:06 +02:00
} else {
2024-10-08 23:51:51 +02:00
$vatratecode = $line -> tva_tx ;
if ( $line -> vat_src_code ) {
$vatratecode .= ' (' . $line -> vat_src_code . ')' ;
}
$result = $invoice -> updateline ( $line -> id , $line -> desc , $line -> subprice , $line -> qty , $number , $line -> date_start , $line -> date_end , $vatratecode , $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 );
2022-05-03 09:35:06 +02:00
}
2021-07-06 03:53:42 +02:00
}
2021-02-26 21:17:52 +01:00
}
2020-01-28 22:21:19 +01:00
}
2020-03-11 12:30:07 +01:00
2022-05-03 09:35:06 +02:00
// Reload data
$invoice -> fetch ( $placeid );
2024-01-07 13:38:13 +01:00
} elseif ( $action == 'update_reduction_global' && $user -> hasRight ( 'takepos' , 'editlines' )) {
2022-05-03 09:35:06 +02:00
foreach ( $invoice -> lines as $line ) {
2024-10-08 23:51:51 +02:00
$vatratecode = $line -> tva_tx ;
if ( $line -> vat_src_code ) {
$vatratecode .= ' (' . $line -> vat_src_code . ')' ;
}
$result = $invoice -> updateline ( $line -> id , $line -> desc , $line -> subprice , $line -> qty , $number , $line -> date_start , $line -> date_end , $vatratecode , $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 );
2022-05-03 09:35:06 +02:00
}
2018-09-28 13:31:41 +02:00
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid );
2020-02-22 11:30:48 +01:00
}
2018-12-07 17:02:06 +01:00
2024-03-07 20:16:48 +01:00
if ( $action == " setbatch " && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
2023-11-11 12:23:12 +01:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
2024-08-29 19:45:11 +02:00
$warehouseid = ( GETPOSTINT ( 'warehouseid' ) > 0 ? GETPOSTINT ( 'warehouseid' ) : getDolGlobalInt ( $constantforkey )); // Get the warehouse id from GETPOSTINT('warehouseid'), otherwise use default setup.
2024-04-30 11:01:37 +02:00
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet SET batch = ' " . $db -> escape ( $batch ) . " ', fk_warehouse = " . (( int ) $warehouseid );
$sql .= " WHERE rowid= " . (( int ) $idoflineadded );
2023-11-11 12:23:12 +01:00
$db -> query ( $sql );
}
2024-01-07 16:31:44 +01:00
if ( $action == " order " && $placeid != 0 && ( $user -> hasRight ( 'takepos' , 'run' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' ))) {
2022-05-03 09:35:06 +02:00
include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2024-02-06 17:05:52 +01:00
if (( isModEnabled ( 'receiptprinter' ) && getDolGlobalInt ( 'TAKEPOS_PRINTER_TO_USE' . $term ) > 0 ) || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " receiptprinter " || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " takeposconnector " ) {
2022-05-03 09:35:06 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/dolreceiptprinter.class.php' ;
$printer = new dolReceiptPrinter ( $db );
}
$sql = " SELECT label FROM " . MAIN_DB_PREFIX . " takepos_floor_tables where rowid= " . (( int ) $place );
$resql = $db -> query ( $sql );
$row = $db -> fetch_object ( $resql );
$headerorder = '<html><br><b>' . $langs -> trans ( 'Place' ) . ' ' . $row -> label . '<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>' ;
$order_receipt_printer1 = " " ;
$order_receipt_printer2 = " " ;
$order_receipt_printer3 = " " ;
2023-12-13 15:20:53 +01:00
$catsprinter1 = explode ( ';' , getDolGlobalString ( 'TAKEPOS_PRINTED_CATEGORIES_1' ));
$catsprinter2 = explode ( ';' , getDolGlobalString ( 'TAKEPOS_PRINTED_CATEGORIES_2' ));
$catsprinter3 = explode ( ';' , getDolGlobalString ( 'TAKEPOS_PRINTED_CATEGORIES_3' ));
2022-05-03 09:35:06 +02:00
$linestoprint = 0 ;
foreach ( $invoice -> lines as $line ) {
if ( $line -> special_code == " 4 " ) {
continue ;
2021-02-26 21:17:52 +01:00
}
2022-05-03 09:35:06 +02:00
$c = new Categorie ( $db );
$existing = $c -> containing ( $line -> fk_product , Categorie :: TYPE_PRODUCT , 'id' );
$result = array_intersect ( $catsprinter1 , $existing );
$count = count ( $result );
if ( ! $line -> fk_product ) {
$count ++ ; // Print Free-text item (Unassigned printer) to Printer 1
}
if ( $count > 0 ) {
$linestoprint ++ ;
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='1' where rowid= " . $line -> id ; //Set to print on printer 1
$db -> query ( $sql );
$order_receipt_printer1 .= '<tr><td class="left">' ;
if ( $line -> fk_product ) {
$order_receipt_printer1 .= $line -> product_label ;
} else {
$order_receipt_printer1 .= $line -> description ;
}
$order_receipt_printer1 .= '</td><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>' ;
2021-02-26 21:17:52 +01:00
}
2020-09-07 10:18:17 +02:00
}
2025-02-18 21:48:21 +01:00
if ((( isModEnabled ( 'receiptprinter' ) && getDolGlobalInt ( 'TAKEPOS_PRINTER_TO_USE' . $term ) > 0 ) || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " receiptprinter " || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " takeposconnector " ) && $linestoprint > 0 && $printer !== null ) {
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid ); //Reload object before send to printer
$printer -> orderprinter = 1 ;
echo " <script> " ;
echo " var orderprinter1esc=' " ;
2022-05-24 12:36:11 +02:00
$ret = $printer -> sendToPrinter ( $invoice , getDolGlobalInt ( 'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS' . $_SESSION [ " takeposterminal " ]), getDolGlobalInt ( 'TAKEPOS_ORDER_PRINTER1_TO_USE' . $_SESSION [ " takeposterminal " ])); // PRINT TO PRINTER 1
2022-05-03 09:35:06 +02:00
echo " ';</script> " ;
}
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='4' where special_code='1' and fk_facture= " . $invoice -> id ; // Set as printed
$db -> query ( $sql );
$invoice -> fetch ( $placeid ); //Reload object after set lines as printed
$linestoprint = 0 ;
foreach ( $invoice -> lines as $line ) {
if ( $line -> special_code == " 4 " ) {
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 ) {
$linestoprint ++ ;
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='2' where rowid= " . $line -> id ; //Set to print on printer 2
$db -> query ( $sql );
$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>' ;
2021-02-26 21:17:52 +01:00
}
2020-09-07 10:18:17 +02:00
}
2024-02-06 17:05:52 +01:00
if ((( isModEnabled ( 'receiptprinter' ) && getDolGlobalInt ( 'TAKEPOS_PRINTER_TO_USE' . $term ) > 0 ) || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " receiptprinter " || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " takeposconnector " ) && $linestoprint > 0 ) {
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid ); //Reload object before send to printer
$printer -> orderprinter = 2 ;
echo " <script> " ;
echo " var orderprinter2esc=' " ;
2022-05-24 12:36:11 +02:00
$ret = $printer -> sendToPrinter ( $invoice , getDolGlobalInt ( 'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS' . $_SESSION [ " takeposterminal " ]), getDolGlobalInt ( 'TAKEPOS_ORDER_PRINTER2_TO_USE' . $_SESSION [ " takeposterminal " ])); // PRINT TO PRINTER 2
2022-05-03 09:35:06 +02:00
echo " ';</script> " ;
}
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='4' where special_code='2' and fk_facture= " . $invoice -> id ; // Set as printed
$db -> query ( $sql );
$invoice -> fetch ( $placeid ); //Reload object after set lines as printed
$linestoprint = 0 ;
foreach ( $invoice -> lines as $line ) {
if ( $line -> special_code == " 4 " ) {
continue ;
}
$c = new Categorie ( $db );
$existing = $c -> containing ( $line -> fk_product , Categorie :: TYPE_PRODUCT , 'id' );
$result = array_intersect ( $catsprinter3 , $existing );
$count = count ( $result );
if ( $count > 0 ) {
$linestoprint ++ ;
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='3' where rowid= " . $line -> id ; //Set to print on printer 3
$db -> query ( $sql );
$order_receipt_printer3 .= '<tr>' . $line -> product_label . '<td class="right">' . $line -> qty ;
if ( ! empty ( $line -> array_options [ 'options_order_notes' ])) {
$order_receipt_printer3 .= " <br>( " . $line -> array_options [ 'options_order_notes' ] . " ) " ;
}
$order_receipt_printer3 .= '</td></tr>' ;
2021-02-26 21:17:52 +01:00
}
2020-10-12 22:07:05 +02:00
}
2025-02-18 21:48:21 +01:00
if ((( isModEnabled ( 'receiptprinter' ) && getDolGlobalInt ( 'TAKEPOS_PRINTER_TO_USE' . $term ) > 0 ) || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " receiptprinter " || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " takeposconnector " ) && $linestoprint > 0 && $printer !== null ) {
2022-05-03 09:35:06 +02:00
$invoice -> fetch ( $placeid ); //Reload object before send to printer
$printer -> orderprinter = 3 ;
echo " <script> " ;
echo " var orderprinter3esc=' " ;
2022-05-24 12:36:11 +02:00
$ret = $printer -> sendToPrinter ( $invoice , getDolGlobalInt ( 'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS' . $_SESSION [ " takeposterminal " ]), getDolGlobalInt ( 'TAKEPOS_ORDER_PRINTER3_TO_USE' . $_SESSION [ " takeposterminal " ])); // PRINT TO PRINTER 3
2022-05-03 09:35:06 +02:00
echo " ';</script> " ;
}
$sql = " UPDATE " . MAIN_DB_PREFIX . " facturedet set special_code='4' where special_code='3' and fk_facture= " . $invoice -> id ; // Set as printed
$db -> query ( $sql );
$invoice -> fetch ( $placeid ); //Reload object after set lines as printed
2020-10-12 22:07:05 +02:00
}
2018-09-28 13:31:41 +02:00
2024-01-07 13:38:13 +01:00
if (( $action == " valid " || $action == " history " || $action == 'creditnote' ) && $user -> hasRight ( 'takepos' , 'run' )) {
2022-05-03 09:35:06 +02: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' ) . " - " ;
$remaintopay = $invoice -> getRemainToPay ();
if ( $remaintopay > 0 ) {
$sectionwithinvoicelink .= $langs -> trans ( 'RemainToPay' ) . ': <span class="amountremaintopay" style="font-size: unset">' . price ( $remaintopay , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</span>' ;
2021-02-26 21:17:52 +01:00
} else {
2022-05-03 09:35:06 +02:00
if ( $invoice -> paye ) {
$sectionwithinvoicelink .= '<span class="amountpaymentcomplete" style="font-size: unset">' . $langs -> trans ( " Paid " ) . '</span>' ;
} else {
$sectionwithinvoicelink .= $langs -> trans ( 'BillShortStatusValidated' );
}
2021-02-26 21:17:52 +01:00
}
2024-02-06 17:05:52 +01:00
2022-05-03 09:35:06 +02:00
$sectionwithinvoicelink .= '</span><br>' ;
2023-05-22 13:43:21 +02:00
if ( getDolGlobalInt ( 'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT' )) {
2023-05-17 18:09:52 +02:00
$sectionwithinvoicelink .= ' <a target="_blank" class="button" href="' . DOL_URL_ROOT . '/document.php?token=' . newToken () . '&modulepart=facture&file=' . $invoice -> ref . '/' . $invoice -> ref . '.pdf">Invoice</a>' ;
} elseif ( getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " takeposconnector " ) {
2024-11-22 12:29:00 +01:00
if ( getDolGlobalString ( 'TAKEPOS_PRINT_SERVER' ) && filter_var ( getDolGlobalString ( 'TAKEPOS_PRINT_SERVER' ), FILTER_VALIDATE_URL ) == true ) {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="TakeposConnector(' . $placeid . ')">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2022-05-03 09:35:06 +02:00
} else {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="TakeposPrinting(' . $placeid . ')">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2022-05-03 09:35:06 +02:00
}
2024-02-06 17:05:52 +01:00
} elseif (( isModEnabled ( 'receiptprinter' ) && getDolGlobalInt ( 'TAKEPOS_PRINTER_TO_USE' . $term ) > 0 ) || getDolGlobalString ( 'TAKEPOS_PRINT_METHOD' ) == " receiptprinter " ) {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="DolibarrTakeposPrinting(' . $placeid . ')">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2021-02-26 21:17:52 +01:00
} else {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="Print(' . $placeid . ')">' . $langs -> trans ( 'PrintTicket' ) . '</button>' ;
2022-05-03 09:35:06 +02:00
if ( getDolGlobalString ( 'TAKEPOS_PRINT_WITHOUT_DETAILS' )) {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="PrintBox(' . $placeid . ', \'without_details\')">' . $langs -> trans ( 'PrintWithoutDetails' ) . '</button>' ;
2022-05-03 09:35:06 +02:00
}
if ( getDolGlobalString ( 'TAKEPOS_GIFT_RECEIPT' )) {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonprint" type="button" onclick="Print(' . $placeid . ', 1)">' . $langs -> trans ( 'GiftReceipt' ) . '</button>' ;
2022-05-03 09:35:06 +02:00
}
2021-10-07 09:51:55 +02:00
}
2023-11-27 13:26:44 +01:00
if ( getDolGlobalString ( 'TAKEPOS_EMAIL_TEMPLATE_INVOICE' ) && getDolGlobalInt ( 'TAKEPOS_EMAIL_TEMPLATE_INVOICE' ) > 0 ) {
2023-04-30 04:26:50 +02:00
$sectionwithinvoicelink .= ' <button id="buttonsend" type="button" onclick="SendTicket(' . $placeid . ')">' . $langs -> trans ( 'SendTicket' ) . '</button>' ;
2020-08-02 11:13:41 +02:00
}
2019-11-07 15:12:37 +01:00
2022-05-31 08:39:48 +02:00
if ( $remaintopay <= 0 && getDolGlobalString ( 'TAKEPOS_AUTO_PRINT_TICKETS' ) && $action != " history " ) {
2022-05-03 09:35:06 +02:00
$sectionwithinvoicelink .= '<script type="text/javascript">$("#buttonprint").click();</script>' ;
}
2021-02-26 21:17:52 +01:00
}
2019-10-23 22:05:37 +02:00
}
2019-03-27 15:42:53 +01:00
2024-01-07 12:49:43 +01:00
2019-03-27 15:42:53 +01:00
/*
* View
*/
2019-03-27 17:50:23 +01:00
$form = new Form ( $db );
2022-08-22 01:56:19 +02:00
// llxHeader
if (( getDolGlobalString ( 'TAKEPOS_PHONE_BASIC_LAYOUT' ) == 1 && $conf -> browser -> layout == 'phone' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
2022-08-22 00:04:04 +02:00
$title = 'TakePOS - Dolibarr ' . DOL_VERSION ;
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'MAIN_APPLICATION_TITLE' )) {
2023-10-15 18:41:39 +02:00
$title = 'TakePOS - ' . getDolGlobalString ( 'MAIN_APPLICATION_TITLE' );
2022-08-22 00:04:04 +02:00
}
$head = ' < meta name = " apple-mobile-web-app-title " content = " TakePOS " />
< 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 " /> ' ;
$arrayofcss = array (
'/takepos/css/pos.css.php' ,
);
$arrayofjs = array ( '/takepos/js/jquery.colorbox-min.js' );
$disablejs = 0 ;
$disablehead = 0 ;
top_htmlhead ( $head , $title , $disablejs , $disablehead , $arrayofjs , $arrayofcss );
2022-08-22 01:56:19 +02:00
print '<body>' . " \n " ;
} else {
top_httphead ( 'text/html' , 1 );
2022-08-22 00:04:04 +02:00
}
2018-09-28 13:31:41 +02:00
?>
2022-08-22 01:56:19 +02:00
<!-- invoice . php -->
2021-11-29 15:09:18 +01:00
< script type = " text/javascript " >
2018-09-28 13:31:41 +02:00
var selectedline = 0 ;
var selectedtext = " " ;
2024-03-07 20:16:48 +01:00
< ? php if ( $action == " valid " ) {
2023-12-04 13:53:48 +01:00
echo " var place=0; " ;
} ?> // Set to default place after close sale
var placeid =< ? php echo ( $placeid > 0 ? $placeid : 0 ); ?> ;
2019-03-27 17:50:23 +01:00
$ ( document ) . ready ( function () {
2023-12-04 13:53:48 +01:00
var idoflineadded = < ? php echo ( empty ( $idoflineadded ) ? 0 : $idoflineadded ); ?> ;
2019-03-29 12:19:23 +01:00
2021-02-26 21:17:52 +01:00
$ ( '.posinvoiceline' ) . click ( function (){
console . log ( " Click done on " + this . id );
$ ( '.posinvoiceline' ) . removeClass ( " selected " );
$ ( this ) . addClass ( " selected " );
2024-01-07 19:32:47 +01:00
if ( ! this . id ) {
return ;
}
if ( selectedline == this . id ) {
return ; // If is already selected
} else {
selectedline = this . id ;
}
2021-02-26 21:17:52 +01:00
selectedtext = $ ( '#' + selectedline ) . find ( " td:first " ) . html ();
2020-05-08 17:25:48 +02:00
< ? php
2020-05-15 13:55:31 +02:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
2024-01-07 20:00:21 +01:00
print '$("#phonediv1").load("' . DOL_URL_ROOT . '/takepos/public/auto_order.php?action=editline&token=' . newToken () . ' & placeid = " +placeid+ " & selectedline = " +selectedline, function() {
2020-05-08 17:25:48 +02:00
}); ' ;
}
?>
2021-02-26 21:17:52 +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
2021-09-02 21:14:01 +02:00
if ( $action == " order " && ! empty ( $order_receipt_printer1 )) {
2024-11-22 12:29:00 +01:00
if ( filter_var ( getDolGlobalString ( 'TAKEPOS_PRINT_SERVER' ), FILTER_VALIDATE_URL ) == true ) {
2020-11-12 22:31:32 +01:00
?>
$ . ajax ({
type : " POST " ,
2024-11-22 12:29:00 +01:00
url : '<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>/printer/index.php' ,
2020-11-12 22:31:32 +01:00
data : 'invoice=' + orderprinter1esc
});
< ? php
2021-02-26 21:17:52 +01:00
} else {
2020-11-12 22:31:32 +01:00
?>
$ . ajax ({
type : " POST " ,
2024-11-22 12:29:00 +01:00
url : 'http://<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>:8111/print' ,
2020-11-12 22:31:32 +01:00
data : ' < ? php
print $headerorder . $order_receipt_printer1 . $footerorder ; ?> '
});
< ? php
}
2018-09-28 13:31:41 +02:00
}
2018-12-07 08:04:40 +01:00
2021-09-02 21:14:01 +02:00
if ( $action == " order " && ! empty ( $order_receipt_printer2 )) {
2024-11-22 12:29:00 +01:00
if ( filter_var ( getDolGlobalString ( 'TAKEPOS_PRINT_SERVER' ), FILTER_VALIDATE_URL ) == true ) {
2020-11-12 22:31:32 +01:00
?>
$ . ajax ({
type : " POST " ,
2024-11-22 12:29:00 +01:00
url : '<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>/printer/index.php?printer=2' ,
2020-11-12 22:31:32 +01:00
data : 'invoice=' + orderprinter2esc
});
< ? php
2021-02-26 21:17:52 +01:00
} else {
2020-11-12 22:31:32 +01:00
?>
$ . ajax ({
type : " POST " ,
2024-11-22 12:29:00 +01:00
url : 'http://<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>:8111/print2' ,
2020-11-12 22:31:32 +01:00
data : ' < ? php
print $headerorder . $order_receipt_printer2 . $footerorder ; ?> '
});
2021-02-26 21:17:52 +01:00
< ? php
2020-11-12 22:31:32 +01:00
}
}
2021-09-02 21:14:01 +02:00
if ( $action == " order " && ! empty ( $order_receipt_printer3 )) {
2024-11-22 12:29:00 +01:00
if ( filter_var ( getDolGlobalString ( 'TAKEPOS_PRINT_SERVER' ), FILTER_VALIDATE_URL ) == true ) {
2020-11-12 22:31:32 +01:00
?>
$ . ajax ({
type : " POST " ,
2024-11-22 12:29:00 +01:00
url : '<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>/printer/index.php?printer=3' ,
2020-11-12 22:31:32 +01:00
data : 'invoice=' + orderprinter3esc
});
< ? php
}
2018-12-07 17:02:06 +01:00
}
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 " ) {
2020-09-07 10:18:17 +02:00
?>
2023-05-23 17:52:34 +02:00
parent . ClearSearch ( true );
2021-02-26 21:17:52 +01:00
< ? php
2018-12-07 17:02:06 +01:00
}
2018-12-07 08:04:40 +01:00
2019-03-27 15:42:53 +01:00
2021-09-02 21:14:01 +02:00
if ( $action == " temp " && ! empty ( $ticket_printer1 )) {
2020-09-07 10:18:17 +02:00
?>
2021-02-26 21:17:52 +01:00
$ . ajax ({
type : " POST " ,
2024-11-22 12:29:00 +01:00
url : 'http://<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>:8111/print' ,
2021-02-26 21:17:52 +01:00
data : ' < ? php
2020-09-07 10:18:17 +02:00
print $header_soc . $header_ticket . $body_ticket . $ticket_printer1 . $ticket_total . $footer_ticket ; ?> '
2021-02-26 21:17:52 +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 " ) {
2020-09-07 10:18:17 +02:00
?>
2021-02-26 21:17:52 +01:00
$ ( '#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
{
2021-02-26 21:17:52 +01:00
console . log ( " Open box to select the Print/Send form " );
2021-04-27 19:33:11 +02:00
$ . colorbox ({ href : " send.php?facid= " + id , width : " 70% " , height : " 30% " , transition : " none " , iframe : " true " , title : '<?php echo dol_escape_js($langs->trans("SendTicket")); ?>' });
2023-05-01 14:33:08 +02:00
return true ;
2019-08-24 16:46:04 +02:00
}
2018-09-28 13:31:41 +02:00
2021-10-07 09:51:55 +02:00
function PrintBox ( id , action ) {
console . log ( " Open box before printing " );
2022-09-12 12:22:00 +02:00
$ . colorbox ({ href : " printbox.php?facid= " + id + " &action= " + action + " &token=<?php echo newToken(); ?> " , width : " 80% " , height : " 200px " , transition : " none " , iframe : " true " , title : " <?php echo $langs->trans ( " PrintWithoutDetails " ); ?> " });
2023-05-01 14:33:08 +02:00
return true ;
2021-10-07 09:51:55 +02:00
}
2020-08-02 11:13:41 +02:00
function Print ( id , gift ){
2021-04-27 19:33:11 +02:00
console . log ( " Call Print() to generate the receipt. " );
$ . colorbox ({ href : " receipt.php?facid= " + id + " &gift= " + gift , width : " 40% " , height : " 90% " , transition : " none " , iframe : " true " , title : '<?php echo dol_escape_js($langs->trans("PrintTicket")); ?>' });
2023-05-01 14:33:08 +02:00
return true ;
2018-09-28 13:31:41 +02:00
}
function TakeposPrinting ( id ){
2021-02-26 21:17:52 +01:00
var receipt ;
2020-10-05 16:38:40 +02:00
console . log ( " TakeposPrinting " + id );
2022-12-21 19:33:02 +01:00
$ . get ( " receipt.php?facid= " + id , function ( data , status ) {
2021-02-26 21:17:52 +01:00
receipt = data . replace ( / ([ ^> \r\n ] ? )( \r\n | \n\r | \r | \n ) / g , '' );
$ . ajax ({
type : " POST " ,
2021-07-08 12:17:32 +02:00
url : 'http://<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>:8111/print' ,
2021-02-26 21:17:52 +01:00
data : receipt
});
});
2023-05-01 14:33:08 +02:00
return true ;
2018-09-28 13:31:41 +02:00
}
2020-04-11 22:19:36 +02:00
function TakeposConnector ( id ){
2020-10-05 16:38:40 +02:00
console . log ( " TakeposConnector " + id );
2022-09-12 12:22:00 +02:00
$ . get ( " <?php echo DOL_URL_ROOT; ?>/takepos/ajax/ajax.php?action=printinvoiceticket&token=<?php echo newToken(); ?>&term=<?php echo urlencode(isset( $_SESSION["takeposterminal"] ) ? $_SESSION["takeposterminal"] : ''); ?>&id= " + id + " &token=<?php echo currentToken(); ?> " , function ( data , status ) {
2021-02-26 21:17:52 +01:00
$ . ajax ({
2020-10-04 22:50:27 +02:00
type : " POST " ,
2021-07-08 12:17:32 +02:00
url : '<?php print getDolGlobalString(' TAKEPOS_PRINT_SERVER '); ?>/printer/index.php' ,
2020-10-04 22:50:27 +02:00
data : 'invoice=' + data
});
2021-02-26 21:17:52 +01:00
});
2023-05-01 14:33:08 +02:00
return true ;
2020-04-11 22:19:36 +02:00
}
2024-01-20 17:16:16 +01:00
// Call the ajax to execute the print.
// With some external module another method may be called.
2019-11-03 00:50:58 +01:00
function DolibarrTakeposPrinting ( id ) {
2024-01-20 17:16:16 +01:00
console . log ( " DolibarrTakeposPrinting Printing invoice ticket " + id );
2021-02-26 21:17:52 +01:00
$ . ajax ({
type : " GET " ,
2021-06-17 03:37:52 +02:00
data : { token : '<?php echo currentToken(); ?>' },
2022-09-12 12:22:00 +02:00
url : " <?php print DOL_URL_ROOT.'/takepos/ajax/ajax.php?action=printinvoiceticket&token='.newToken().'&term='.urlencode(isset( $_SESSION["takeposterminal"] ) ? $_SESSION["takeposterminal"] : '').'&id='; ?> " + id ,
2024-01-20 17:16:16 +01:00
2021-02-26 21:17:52 +01:00
});
2023-05-01 14:33:08 +02:00
return true ;
2019-11-03 00:50:58 +01:00
}
2020-03-08 22:33:56 +01:00
2024-08-29 19:45:11 +02:00
// Call url to generate a credit note (with same lines) from existing invoice
2020-10-25 20:03:25 +01:00
function CreditNote () {
2024-08-29 19:45:11 +02:00
$ ( " #poslines " ) . load ( " <?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=creditnote&token=<?php echo newToken() ?>&invoiceid= " + placeid , function () { });
2023-05-01 14:33:08 +02:00
return true ;
2020-10-25 20:03:25 +01:00
}
2024-08-29 19:45:11 +02:00
// Call url to add notes
2021-04-14 00:15:02 +02:00
function SetNote () {
2024-08-29 19:45:11 +02:00
$ ( " #poslines " ) . load ( " <?php print DOL_URL_ROOT; ?>/takepos/invoice.php?action=addnote&token=<?php echo newToken() ?>&invoiceid= " + placeid + " &idline= " + selectedline , { " addnote " : $ ( " #textinput " ) . val () });
2023-05-01 14:33:08 +02:00
return true ;
2021-04-14 00:15:02 +02:00
}
2020-03-16 13:27:10 +01:00
2020-03-08 22:33:56 +01:00
$ ( document ) . ready ( function () {
2021-01-02 15:36:19 +01:00
console . log ( " Set customer info and sales in header placeid=<?php echo $placeid ; ?> status=<?php echo $invoice->statut ; ?> " );
2020-03-16 13:27:10 +01:00
2021-02-26 21:17:52 +01:00
< ? php
2020-09-07 10:18:17 +02:00
$s = $langs -> trans ( " Customer " );
2023-05-17 15:42:53 +02:00
if ( $invoice -> id > 0 && ( $invoice -> socid != getDolGlobalString ( $constforcompanyid ))) {
2020-09-07 10:18:17 +02:00
$s = $soc -> name ;
2023-10-13 16:19:10 +02:00
if ( getDolGlobalInt ( 'TAKEPOS_CHOOSE_CONTACT' )) {
$contactids = $invoice -> getIdContact ( 'external' , 'BILLING' );
$contactid = $contactids [ 0 ];
if ( $contactid > 0 ) {
$contact = new Contact ( $db );
$contact -> fetch ( $contactid );
$s .= " - " . $contact -> getFullName ( $langs );
}
}
2024-11-12 02:24:25 +01:00
} elseif ( getDolGlobalInt ( " TAKEPOS_NO_GENERIC_THIRDPARTY " )) {
print '$("#idcustomer").val("");' ;
2020-09-07 10:18:17 +02:00
}
?>
2020-03-16 13:27:10 +01:00
2021-02-26 21:17:52 +01:00
$ ( " #customerandsales " ) . html ( '' );
2021-12-20 13:39:34 +01:00
$ ( " #shoppingcart " ) . html ( '' );
2020-04-20 13:20:09 +02:00
2023-10-13 16:19:10 +02:00
< ? php if ( getDolGlobalInt ( 'TAKEPOS_CHOOSE_CONTACT' ) == 0 ) { ?>
2025-02-18 21:48:21 +01:00
$ ( " #customerandsales " ) . append ( '<a class="valignmiddle tdoverflowmax100 minwidth100" id="customer" onclick="Customer();" title="<?php print dol_escape_js(dol_escape_htmltag((string) $s)); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js((string) $s); ?></a>' );
2023-10-13 16:19:10 +02:00
< ? php } else { ?>
2025-02-18 21:48:21 +01:00
$ ( " #customerandsales " ) . append ( '<a class="valignmiddle tdoverflowmax300 minwidth100" id="contact" onclick="Contact();" title="<?php print dol_escape_js(dol_escape_htmltag((string) $s)); ?>"><span class="fas fa-building paddingrightonly"></span><?php print dol_escape_js((string) $s); ?></a>' );
2023-10-13 16:19:10 +02:00
< ? php } ?>
2020-03-16 13:27:10 +01:00
< ? php
2020-03-23 14:12:48 +01:00
$sql = " SELECT rowid, datec, ref FROM " . MAIN_DB_PREFIX . " facture " ;
2024-03-31 13:56:44 +02:00
$sql .= " WHERE entity IN ( " . getEntity ( 'invoice' ) . " ) " ;
2023-11-27 12:08:48 +01:00
if ( ! getDolGlobalString ( 'TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED' )) {
2021-01-02 15:36:19 +01:00
// By default, only invoices with a ref not already defined can in list of open invoice we can edit.
2024-03-31 13:56:44 +02:00
$sql .= " AND ref LIKE '(PROV-POS " . $db -> escape ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' ) . " -0%' " ;
2021-01-02 15:36:19 +01:00
} else {
// If TAKEPOS_CAN_EDIT_IF_ALREADY_VALIDATED set, we show also draft invoice that already has a reference defined
2025-02-18 21:48:21 +01:00
$sql .= " AND pos_source = ' " . $db -> escape (( string ) $_SESSION [ " takeposterminal " ]) . " ' " ;
2021-01-02 15:36:19 +01:00
$sql .= " AND module_source = 'takepos' " ;
}
2021-01-02 15:49:30 +01:00
2020-04-10 10:59:32 +02:00
$sql .= $db -> order ( 'datec' , 'ASC' );
2020-03-22 14:50:09 +01:00
$resql = $db -> query ( $sql );
if ( $resql ) {
2021-07-08 12:17:32 +02:00
$max_sale = 0 ;
2020-03-22 14:50:09 +01:00
while ( $obj = $db -> fetch_object ( $resql )) {
2021-12-20 13:39:34 +01:00
echo '$("#shoppingcart").append(\'' ;
2021-07-13 14:07:35 +02:00
echo '<a class="valignmiddle" title="' . dol_escape_js ( $langs -> trans ( " SaleStartedAt " , dol_print_date ( $db -> jdate ( $obj -> datec ), '%H:%M' , 'tzuser' )) . ' - ' . $obj -> ref ) . '" onclick="place=\\\'' ;
2020-04-10 10:59:32 +02:00
$num_sale = str_replace ( " ) " , " " , str_replace ( " (PROV-POS " . $_SESSION [ " takeposterminal " ] . " - " , " " , $obj -> ref ));
2020-03-22 14:50:09 +01:00
echo $num_sale ;
2021-02-26 21:17:52 +01:00
if ( str_replace ( " - " , " " , $num_sale ) > $max_sale ) {
$max_sale = str_replace ( " - " , " " , $num_sale );
}
2021-01-02 15:36:19 +01:00
echo '\\\'; invoiceid=\\\'' ;
echo $obj -> rowid ;
echo '\\\'; Refresh();">' ;
2021-02-26 21:17:52 +01:00
if ( $placeid == $obj -> rowid ) {
2022-11-06 23:18:16 +01:00
echo '<span class="basketselected">' ;
} else {
echo '<span class="basketnotselected">' ;
2021-02-26 21:17:52 +01:00
}
2021-03-29 14:03:19 +02:00
echo '<span class="fa fa-shopping-cart paddingright"></span>' . dol_print_date ( $db -> jdate ( $obj -> datec ), '%H:%M' , 'tzuser' );
2022-11-06 23:18:16 +01:00
echo '</span>' ;
2020-03-22 14:50:09 +01:00
echo '</a>\');' ;
}
2021-12-20 13:39:34 +01:00
echo '$("#shoppingcart").append(\'<a onclick="place=\\\'0-' ;
2020-04-10 10:59:32 +02:00
echo $max_sale + 1 ;
2021-03-29 14:03:19 +02:00
echo '\\\'; invoiceid=0; Refresh();"><div><span class="fa fa-plus" title="' . dol_escape_htmltag ( $langs -> trans ( " StartAParallelSale " )) . '"><span class="fa fa-shopping-cart"></span></div></a>\');' ;
2020-03-23 14:12:48 +01:00
} else {
dol_print_error ( $db );
2020-03-22 14:50:09 +01:00
}
2020-03-22 15:24:32 +01:00
2020-03-16 13:27:10 +01:00
$s = '' ;
2021-12-20 13:39:34 +01:00
$idwarehouse = 0 ;
2021-09-02 21:14:01 +02:00
$constantforkey = 'CASHDESK_NO_DECREASE_STOCK' . ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' );
2022-08-26 17:03:20 +02:00
if ( isModEnabled ( 'stock' )) {
2023-10-09 15:44:57 +02:00
if ( getDolGlobalString ( $constantforkey ) != " 1 " ) {
2021-12-20 13:39:34 +01:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . ( isset ( $_SESSION [ " takeposterminal " ]) ? $_SESSION [ " takeposterminal " ] : '' );
2025-02-18 21:48:21 +01:00
$idwarehouse = getDolGlobalInt ( $constantforkey );
2021-12-20 13:39:34 +01:00
if ( $idwarehouse > 0 ) {
$s = '<span class="small">' ;
$warehouse = new Entrepot ( $db );
$warehouse -> fetch ( $idwarehouse );
$s .= '<span class="hideonsmartphone">' . $langs -> trans ( " Warehouse " ) . '<br></span>' . $warehouse -> ref ;
if ( $warehouse -> statut == Entrepot :: STATUS_CLOSED ) {
$s .= ' (' . $langs -> trans ( " Closed " ) . ')' ;
}
$s .= '</span>' ;
print " $ ('#infowarehouse').html(' " . dol_escape_js ( $s ) . " '); " ;
print '$("#infowarehouse").css("display", "inline-block");' ;
} else {
$s = '<span class="small hideonsmartphone">' ;
$s .= $langs -> trans ( " StockChangeDisabled " ) . '<br>' . $langs -> trans ( " NoWarehouseDefinedForTerminal " );
$s .= '</span>' ;
print " $ ('#infowarehouse').html(' " . dol_escape_js ( $s ) . " '); " ;
if ( ! empty ( $conf -> dol_optimize_smallscreen )) {
print '$("#infowarehouse").css("display", "none");' ;
}
}
} else {
$s = '<span class="small hideonsmartphone">' . $langs -> trans ( " StockChangeDisabled " ) . '</span>' ;
print " $ ('#infowarehouse').html(' " . dol_escape_js ( $s ) . " '); " ;
if ( ! empty ( $conf -> dol_optimize_smallscreen )) {
print '$("#infowarehouse").css("display", "none");' ;
}
}
2020-09-07 10:18:17 +02:00
}
2020-03-16 13:27:10 +01:00
// Module Adherent
$s = '' ;
2024-02-27 15:30:37 +01:00
if ( isModEnabled ( 'member' ) && $invoice -> socid > 0 && $invoice -> socid != getDolGlobalInt ( $constforcompanyid )) {
2020-03-16 13:27:10 +01:00
$s = '<span class="small">' ;
require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php' ;
$langs -> load ( " members " );
$s .= $langs -> trans ( " Member " ) . ': ' ;
$adh = new Adherent ( $db );
2025-02-18 21:48:21 +01:00
$result = $adh -> fetch ( 0 , '' , $invoice -> socid );
2021-02-26 21:17:52 +01:00
if ( $result > 0 ) {
2020-03-16 13:27:10 +01:00
$adh -> ref = $adh -> getFullName ( $langs );
2023-12-04 13:53:48 +01:00
if ( empty ( $adh -> statut ) || $adh -> statut == Adherent :: STATUS_EXCLUDED ) {
2021-02-26 21:17:52 +01:00
$s .= " <s> " ;
}
2020-04-10 10:59:32 +02:00
$s .= $adh -> getFullName ( $langs );
$s .= ' - ' . $adh -> type ;
2021-02-26 21:17:52 +01:00
if ( $adh -> datefin ) {
2020-04-10 10:59:32 +02:00
$s .= '<br>' . $langs -> trans ( " SubscriptionEndDate " ) . ': ' . dol_print_date ( $adh -> datefin , 'day' );
2020-03-16 13:27:10 +01:00
if ( $adh -> hasDelay ()) {
2020-04-10 10:59:32 +02:00
$s .= " " . img_warning ( $langs -> trans ( " Late " ));
2020-03-16 13:27:10 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$s .= '<br>' . $langs -> trans ( " SubscriptionNotReceived " );
2021-02-26 21:17:52 +01:00
if ( $adh -> statut > 0 ) {
$s .= " " . img_warning ( $langs -> trans ( " Late " )); // displays delay Pictogram only if not a draft and not terminated
}
}
2021-10-24 19:21:51 +02:00
if ( empty ( $adh -> statut ) || $adh -> statut == Adherent :: STATUS_EXCLUDED ) {
2021-02-26 21:17:52 +01:00
$s .= " </s> " ;
2020-03-16 13:27:10 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-04-10 10:59:32 +02:00
$s .= '<br>' . $langs -> trans ( " ThirdpartyNotLinkedToMember " );
2020-03-16 13:27:10 +01:00
}
2020-04-10 10:59:32 +02:00
$s .= '</span>' ;
2020-03-16 13:27:10 +01:00
}
?>
$ ( " #moreinfo " ) . html ( '<?php print dol_escape_js($s); ?>' );
2020-03-08 22:33:56 +01:00
});
2021-08-08 19:14:28 +02:00
< ? php
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'TAKEPOS_CUSTOMER_DISPLAY' )) {
2024-01-23 23:25:15 +01:00
echo " function CustomerDisplay() { " ;
echo " var line1=' " . $CUSTOMER_DISPLAY_line1 . " '.substring(0,20); " ;
echo " line1=line1.padEnd(20); " ;
echo " var line2=' " . $CUSTOMER_DISPLAY_line2 . " '.substring(0,20); " ;
echo " line2=line2.padEnd(20); " ;
echo " $ .ajax( {
2021-08-08 19:14:28 +02:00
type : 'GET' ,
data : { text : line1 + line2 },
url : '".getDolGlobalString(' TAKEPOS_PRINT_SERVER ')."/display/index.php' ,
}); " ;
2024-01-23 23:25:15 +01:00
echo " } " ;
2021-08-08 19:14:28 +02: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
2020-03-16 15:41:21 +01:00
// Add again js for footer because this content is injected into index.php page so all init
2019-03-27 17:50:23 +01:00
// for tooltip and other js beautifiers must be reexecuted too.
2021-02-26 21:17:52 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2020-09-07 10:18:17 +02:00
print " \n " . '<!-- Includes JS Footer of Dolibarr -->' . " \n " ;
2021-07-08 12:17:32 +02:00
print '<script src="' . DOL_URL_ROOT . '/core/js/lib_foot.js.php?lang=' . $langs -> defaultlang . '"></script>' . " \n " ;
2019-03-27 17:50:23 +01:00
}
2024-01-07 19:32:47 +01:00
$usediv = ( GETPOST ( 'format' ) == 'div' );
2024-03-16 22:53:10 +01:00
print '<!-- invoice.php place=' . ( int ) $place . ' invoice=' . $invoice -> ref . ' usediv=' . json_encode ( $usediv ) . ', mobilepage=' . ( empty ( $mobilepage ) ? '' : $mobilepage ) . ' $_SESSION["basiclayout"]=' . ( empty ( $_SESSION [ " basiclayout " ]) ? '' : $_SESSION [ " basiclayout " ]) . ' conf TAKEPOS_BAR_RESTAURANT=' . getDolGlobalString ( 'TAKEPOS_BAR_RESTAURANT' ) . ' -->' . " \n " ;
2018-12-07 21:33:40 +01:00
print '<div class="div-table-responsive-no-min invoice">' ;
2024-01-07 19:32:47 +01:00
if ( $usediv ) {
print '<div id="tablelines">' ;
} else {
print '<table id="tablelines" class="noborder noshadow postablelines centpercent">' ;
}
2020-10-13 11:00:56 +02:00
if ( $sectionwithinvoicelink && ( $mobilepage == " invoice " || $mobilepage == " " )) {
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( 'TAKEPOS_SHOW_HT' )) {
2021-02-26 21:17:52 +01:00
print '<tr><td colspan="5">' . $sectionwithinvoicelink . '</td></tr>' ;
} else {
2021-02-24 15:48:15 +01:00
print '<tr><td colspan="4">' . $sectionwithinvoicelink . '</td></tr>' ;
}
2020-10-04 15:01:22 +02:00
}
2024-01-07 20:00:21 +01:00
// Show the list of selected product
2024-01-07 19:32:47 +01:00
if ( ! $usediv ) {
print '<tr class="liste_titre nodrag nodrop">' ;
print '<td class="linecoldescription">' ;
}
2020-07-07 03:50:14 +02:00
// In phone version only show when it is invoice page
2021-07-08 12:17:32 +02:00
if ( empty ( $mobilepage ) || $mobilepage == " invoice " ) {
2023-09-09 14:29:16 +02:00
print '<!-- hidden var used by some js functions -->' ;
2020-10-04 15:01:22 +02:00
print '<input type="hidden" name="invoiceid" id="invoiceid" value="' . $invoice -> id . '">' ;
2023-09-09 14:29:16 +02:00
print '<input type="hidden" name="thirdpartyid" id="thirdpartyid" value="' . $invoice -> socid . '">' ;
2020-07-07 03:50:14 +02:00
}
2024-01-07 19:32:47 +01:00
if ( ! $usediv ) {
if ( getDolGlobalString ( 'TAKEPOS_BAR_RESTAURANT' )) {
$sql = " SELECT floor, label FROM " . MAIN_DB_PREFIX . " takepos_floor_tables where rowid= " . (( int ) $place );
$resql = $db -> query ( $sql );
$obj = $db -> fetch_object ( $resql );
if ( $obj ) {
$label = $obj -> label ;
$floor = $obj -> floor ;
}
if ( $mobilepage == " invoice " || $mobilepage == " " ) {
// If not on smartphone version or if it is the invoice page
//print 'mobilepage='.$mobilepage;
print '<span class="opacitymedium">' . $langs -> trans ( 'Place' ) . " </span> <b> " . ( empty ( $label ) ? '?' : $label ) . " </b><br> " ;
print '<span class="opacitymedium">' . $langs -> trans ( 'Floor' ) . " </span> <b> " . ( empty ( $floor ) ? '?' : $floor ) . " </b> " ;
}
2019-10-16 16:26:00 +02:00
}
2024-01-07 19:32:47 +01:00
print '</td>' ;
2019-10-16 16:26:00 +02:00
}
2022-05-06 11:34:05 +02:00
2024-01-07 20:00:21 +01:00
// Complete header by hook
2024-03-07 20:16:48 +01:00
$parameters = array ();
$reshook = $hookmanager -> executeHooks ( 'completeTakePosInvoiceHeader' , $parameters , $invoice , $action ); // Note that $action and $object may have been modified by some hooks
2023-12-04 13:53:48 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2022-05-06 11:34:05 +02:00
print $hookmanager -> resPrint ;
2021-07-08 12:17:32 +02:00
if ( empty ( $_SESSION [ " basiclayout " ]) || $_SESSION [ " basiclayout " ] != 1 ) {
2023-05-21 19:03:00 +02:00
if ( getDolGlobalInt ( " TAKEPOS_SHOW_SUBPRICE " )) {
2023-05-19 11:43:44 +02:00
print '<td class="linecolqty right">' . $langs -> trans ( 'PriceUHT' ) . '</td>' ;
}
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>' ;
2021-07-08 12:17:32 +02:00
if ( getDolGlobalString ( 'TAKEPOS_SHOW_HT' )) {
2021-02-26 21:17:52 +01:00
print '<td class="linecolht right nowraponall">' ;
print '<span class="opacitymedium small">' . $langs -> trans ( 'TotalHTShort' ) . '</span><br>' ;
// In phone version only show when it is invoice page
2021-07-08 12:17:32 +02:00
if ( empty ( $mobilepage ) || $mobilepage == " invoice " ) {
2021-02-26 21:17:52 +01:00
print '<span id="linecolht-span-total" style="font-size:1.3em; font-weight: bold;">' . price ( $invoice -> total_ht , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</span>' ;
2024-04-14 03:07:02 +02:00
if ( isModEnabled ( 'multicurrency' ) && ! empty ( $_SESSION [ " takeposcustomercurrency " ]) && $conf -> currency != $_SESSION [ " takeposcustomercurrency " ]) {
2021-02-26 21:17:52 +01:00
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php' ;
$multicurrency = new MultiCurrency ( $db );
$multicurrency -> fetch ( 0 , $_SESSION [ " takeposcustomercurrency " ]);
print '<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">(' . price ( $invoice -> total_ht * $multicurrency -> rate -> rate ) . ' ' . $_SESSION [ " takeposcustomercurrency " ] . ')</span>' ;
}
}
print '</td>' ;
}
2020-07-07 03:50:14 +02:00
print '<td class="linecolht right nowraponall">' ;
print '<span class="opacitymedium small">' . $langs -> trans ( 'TotalTTCShort' ) . '</span><br>' ;
// In phone version only show when it is invoice page
2021-07-08 12:17:32 +02:00
if ( empty ( $mobilepage ) || $mobilepage == " invoice " ) {
2020-07-07 03:50:14 +02:00
print '<span id="linecolht-span-total" style="font-size:1.3em; font-weight: bold;">' . price ( $invoice -> total_ttc , 1 , '' , 1 , - 1 , - 1 , $conf -> currency ) . '</span>' ;
2022-08-26 17:03:20 +02:00
if ( isModEnabled ( 'multicurrency' ) && ! empty ( $_SESSION [ " takeposcustomercurrency " ]) && $conf -> currency != $_SESSION [ " takeposcustomercurrency " ]) {
2020-10-04 14:40:52 +02:00
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php' ;
$multicurrency = new MultiCurrency ( $db );
$multicurrency -> fetch ( 0 , $_SESSION [ " takeposcustomercurrency " ]);
2020-10-07 15:01:28 +02:00
print '<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">(' . price ( $invoice -> total_ttc * $multicurrency -> rate -> rate ) . ' ' . $_SESSION [ " takeposcustomercurrency " ] . ')</span>' ;
2020-10-04 14:40:52 +02:00
}
2020-07-07 03:50:14 +02:00
}
print '</td>' ;
2021-02-26 21:17:52 +01:00
} elseif ( $mobilepage == " invoice " ) {
print '<td class="linecolqty right">' . $langs -> trans ( 'Qty' ) . '</td>' ;
2019-05-26 16:44:17 +02:00
}
2024-01-07 19:32:47 +01:00
if ( ! $usediv ) {
print " </tr> \n " ;
}
2020-01-01 21:54:47 +01:00
2021-07-08 12:17:32 +02:00
if ( ! empty ( $_SESSION [ " basiclayout " ]) && $_SESSION [ " basiclayout " ] == 1 ) {
2021-02-26 21:17:52 +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 );
2020-09-07 10:18:17 +02:00
$categories = $categorie -> get_full_arbo ( 'product' );
2024-03-18 13:20:16 +01:00
$htmlforlines = '' ;
2020-09-07 10:18:17 +02:00
foreach ( $categories as $row ) {
2021-02-26 21:17:52 +01:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
2024-01-07 19:32:47 +01:00
$htmlforlines .= '<div class="leftcat"' ;
2021-02-26 21:17:52 +01:00
} else {
2024-01-07 19:32:47 +01:00
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline"' ;
2021-02-26 21:17:52 +01:00
}
2024-01-07 19:32:47 +01:00
$htmlforlines .= ' onclick="LoadProducts(' . $row [ 'id' ] . ');">' ;
2021-02-26 21:17:52 +01:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
$htmlforlines .= '<img class="imgwrapper" width="33%" src="' . DOL_URL_ROOT . '/takepos/public/auto_order.php?genimg=cat&query=cat&id=' . $row [ 'id' ] . '"><br>' ;
} else {
$htmlforlines .= '<td class="left">' ;
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= $row [ 'label' ];
2021-02-26 21:17:52 +01:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
$htmlforlines .= '</div>' . " \n " ;
} else {
$htmlforlines .= '</td></tr>' . " \n " ;
}
2019-05-26 16:44:17 +02:00
}
print $htmlforlines ;
}
2019-08-26 16:49:25 +02:00
2021-02-26 21:17:52 +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 );
2024-02-22 19:18:00 +01:00
$catid = GETPOSTINT ( 'catid' );
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 ) {
2021-02-26 21:17:52 +01:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
2024-01-07 12:49:43 +01:00
$htmlforlines .= '<div class="leftcat"' ;
2021-02-26 21:17:52 +01:00
} else {
2024-01-07 12:49:43 +01:00
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline"' ;
2021-02-26 21:17:52 +01:00
}
2024-01-07 12:49:43 +01:00
$htmlforlines .= ' onclick="AddProduct(\'' . $place . '\', ' . $row -> id . ')"' ;
$htmlforlines .= '>' ;
2020-05-24 16:30:42 +02:00
if ( defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
$htmlforlines .= '<img class="imgwrapper" width="33%" src="' . DOL_URL_ROOT . '/takepos/public/auto_order.php?genimg=pro&query=pro&id=' . $row -> id . '"><br>' ;
2022-12-31 13:23:09 +01:00
$htmlforlines .= $row -> label . ' ' . price ( $row -> price_ttc , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency );
2020-05-24 16:30:42 +02:00
$htmlforlines .= '</div>' . " \n " ;
2021-02-26 21:17:52 +01:00
} else {
2020-05-24 16:30:42 +02:00
$htmlforlines .= '<td class="left">' ;
$htmlforlines .= $row -> label ;
$htmlforlines .= '<div class="right">' . price ( $row -> price_ttc , 1 , $langs , 1 , - 1 , - 1 , $conf -> currency ) . '</div>' ;
2024-01-07 12:49:43 +01:00
$htmlforlines .= '</td>' ;
2020-05-24 16:30:42 +02:00
$htmlforlines .= '</tr>' . " \n " ;
}
2019-05-26 16:44:17 +02:00
}
print $htmlforlines ;
}
2019-08-26 16:49:25 +02:00
2021-02-26 21:17:52 +01:00
if ( $mobilepage == " places " ) {
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
}
print $htmlforlines ;
}
}
2021-02-26 21:17:52 +01:00
if ( $placeid > 0 ) {
2019-10-16 16:26:00 +02:00
//In Phone basic layout hide some content depends situation
2021-07-08 12:17:32 +02:00
if ( ! empty ( $_SESSION [ " basiclayout " ]) && $_SESSION [ " basiclayout " ] == 1 && $mobilepage != " invoice " && $action != " order " ) {
2021-02-26 21:17:52 +01:00
return ;
}
2019-10-20 15:37:20 +02:00
2024-04-30 12:42:10 +02:00
// Loop on each lines on invoice
2021-02-26 21:17:52 +01:00
if ( is_array ( $invoice -> lines ) && count ( $invoice -> lines )) {
2020-12-04 00:58:51 +01:00
print '<!-- invoice.php show lines of invoices -->' . " \n " ;
2020-09-07 10:18:17 +02:00
$tmplines = array_reverse ( $invoice -> lines );
2021-07-08 12:17:32 +02:00
$htmlsupplements = array ();
2021-02-26 21:17:52 +01:00
foreach ( $tmplines as $line ) {
if ( $line -> fk_parent_line != false ) {
2020-03-12 12:45:44 +01:00
$htmlsupplements [ $line -> fk_parent_line ] .= '<tr class="drag drop oddeven posinvoiceline' ;
2021-02-26 21:17:52 +01:00
if ( $line -> special_code == " 4 " ) {
$htmlsupplements [ $line -> fk_parent_line ] .= ' order' ;
}
2022-05-24 12:36:11 +02:00
$htmlsupplements [ $line -> fk_parent_line ] .= '" id="' . $line -> id . '"' ;
if ( $line -> special_code == " 4 " ) {
2022-06-03 02:31:09 +02:00
$htmlsupplements [ $line -> fk_parent_line ] .= ' title="' . dol_escape_htmltag ( $langs -> trans ( " AlreadyPrinted " )) . '"' ;
2022-05-24 12:36:11 +02:00
}
$htmlsupplements [ $line -> fk_parent_line ] .= '>' ;
2020-03-12 12:45:44 +01:00
$htmlsupplements [ $line -> fk_parent_line ] .= '<td class="left">' ;
$htmlsupplements [ $line -> fk_parent_line ] .= img_picto ( '' , 'rightarrow' );
2021-02-26 21:17:52 +01:00
if ( $line -> product_label ) {
$htmlsupplements [ $line -> fk_parent_line ] .= $line -> product_label ;
}
if ( $line -> product_label && $line -> desc ) {
$htmlsupplements [ $line -> fk_parent_line ] .= '<br>' ;
}
if ( $line -> product_label != $line -> desc ) {
2019-12-08 23:16:49 +01:00
$firstline = dolGetFirstLineOfText ( $line -> desc );
2021-02-26 21:17:52 +01:00
if ( $firstline != $line -> desc ) {
2019-12-08 23:16:49 +01:00
$htmlsupplements [ $line -> fk_parent_line ] .= $form -> textwithpicto ( dolGetFirstLineOfText ( $line -> desc ), $line -> desc );
2020-05-21 15:05:19 +02:00
} else {
2019-12-08 23:16:49 +01:00
$htmlsupplements [ $line -> fk_parent_line ] .= $line -> desc ;
}
}
$htmlsupplements [ $line -> fk_parent_line ] .= '</td>' ;
2022-05-06 11:34:05 +02:00
// complete line by hook
2024-03-07 20:16:48 +01:00
$parameters = array ( 'line' => $line );
$reshook = $hookmanager -> executeHooks ( 'completeTakePosInvoiceParentLine' , $parameters , $invoice , $action ); // Note that $action and $object may have been modified by some hooks
2023-12-04 13:53:48 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2022-05-06 11:34:05 +02:00
$htmlsupplements [ $line -> fk_parent_line ] .= $hookmanager -> resPrint ;
2021-07-08 12:17:32 +02:00
if ( empty ( $_SESSION [ " basiclayout " ]) || $_SESSION [ " basiclayout " ] != 1 ) {
2024-09-23 01:59:14 +02:00
$htmlsupplements [ $line -> fk_parent_line ] .= '<td class="right">' . vatrate ( price2num ( $line -> remise_percent ), true ) . '</td>' ;
2019-12-08 23:16:49 +01:00
$htmlsupplements [ $line -> fk_parent_line ] .= '<td class="right">' . $line -> qty . '</td>' ;
$htmlsupplements [ $line -> fk_parent_line ] .= '<td class="right">' . price ( $line -> total_ttc ) . '</td>' ;
}
$htmlsupplements [ $line -> fk_parent_line ] .= '</tr>' . " \n " ;
continue ;
}
2020-09-08 21:27:28 +02:00
$htmlforlines = '' ;
$htmlforlines .= '<tr class="drag drop oddeven posinvoiceline' ;
if ( $line -> special_code == " 4 " ) {
$htmlforlines .= ' order' ;
}
2022-05-24 12:36:11 +02:00
$htmlforlines .= '" id="' . $line -> id . '"' ;
if ( $line -> special_code == " 4 " ) {
2022-06-03 02:31:09 +02:00
$htmlforlines .= ' title="' . dol_escape_htmltag ( $langs -> trans ( " AlreadyPrinted " )) . '"' ;
2022-05-24 12:36:11 +02:00
}
$htmlforlines .= '>' ;
2020-09-08 21:27:28 +02:00
$htmlforlines .= '<td class="left">' ;
2021-07-08 12:17:32 +02:00
if ( ! empty ( $_SESSION [ " basiclayout " ]) && $_SESSION [ " basiclayout " ] == 1 ) {
2021-02-26 21:17:52 +01:00
$htmlforlines .= '<span class="phoneqty">' . $line -> qty . " </span> x " ;
}
if ( isset ( $line -> product_type )) {
if ( empty ( $line -> product_type )) {
$htmlforlines .= img_object ( '' , 'product' ) . ' ' ;
} else {
$htmlforlines .= img_object ( '' , 'service' ) . ' ' ;
}
2020-09-08 21:27:28 +02:00
}
2024-05-02 20:22:00 +02:00
$tooltiptext = '' ;
2023-11-27 12:08:48 +01:00
if ( ! getDolGlobalString ( 'TAKEPOS_SHOW_N_FIRST_LINES' )) {
2020-09-08 21:27:28 +02:00
if ( $line -> product_ref ) {
$tooltiptext .= '<b>' . $langs -> trans ( " Ref " ) . '</b> : ' . $line -> product_ref . '<br>' ;
$tooltiptext .= '<b>' . $langs -> trans ( " Label " ) . '</b> : ' . $line -> product_label . '<br>' ;
2024-04-30 12:42:10 +02:00
if ( ! empty ( $line -> batch )) {
$tooltiptext .= '<br><b>' . $langs -> trans ( " LotSerial " ) . '</b> : ' . $line -> batch . '<br>' ;
}
if ( ! empty ( $line -> fk_warehouse )) {
$tooltiptext .= '<b>' . $langs -> trans ( " Warehouse " ) . '</b> : ' . $line -> fk_warehouse . '<br>' ;
}
2020-09-08 21:27:28 +02:00
if ( $line -> product_label != $line -> desc ) {
2021-02-26 21:17:52 +01:00
if ( $line -> desc ) {
$tooltiptext .= '<br>' ;
}
2020-09-08 21:27:28 +02:00
$tooltiptext .= $line -> desc ;
}
}
2022-12-08 18:57:58 +01:00
if ( getDolGlobalInt ( 'TAKEPOS_SHOW_PRODUCT_REFERENCE' ) == 1 ) {
2021-11-30 15:41:46 +01:00
$htmlforlines .= $form -> textwithpicto ( $line -> product_label ? '<b>' . $line -> product_ref . '</b> - ' . $line -> product_label : dolGetFirstLineOfText ( $line -> desc , 1 ), $tooltiptext );
2023-08-28 17:34:05 +02:00
} elseif ( getDolGlobalInt ( 'TAKEPOS_SHOW_PRODUCT_REFERENCE' ) == 2 ) {
$htmlforlines .= $form -> textwithpicto ( $line -> product_ref ? '<b>' . $line -> product_ref . '<b>' : dolGetFirstLineOfText ( $line -> desc , 1 ), $tooltiptext );
2021-11-30 16:07:59 +01:00
} else {
2021-11-30 15:41:46 +01:00
$htmlforlines .= $form -> textwithpicto ( $line -> product_label ? $line -> product_label : ( $line -> product_ref ? $line -> product_ref : dolGetFirstLineOfText ( $line -> desc , 1 )), $tooltiptext );
}
2020-09-08 21:27:28 +02:00
} else {
2024-05-02 20:22:00 +02:00
if ( $line -> product_ref ) {
$tooltiptext .= '<b>' . $langs -> trans ( " Ref " ) . '</b> : ' . $line -> product_ref . '<br>' ;
$tooltiptext .= '<b>' . $langs -> trans ( " Label " ) . '</b> : ' . $line -> product_label . '<br>' ;
2021-02-26 21:17:52 +01:00
}
2024-04-30 13:17:59 +02:00
if ( ! empty ( $line -> batch )) {
$tooltiptext .= '<br><b>' . $langs -> trans ( " LotSerial " ) . '</b> : ' . $line -> batch . '<br>' ;
}
if ( ! empty ( $line -> fk_warehouse )) {
$tooltiptext .= '<b>' . $langs -> trans ( " Warehouse " ) . '</b> : ' . $line -> fk_warehouse . '<br>' ;
}
2024-05-02 20:22:00 +02:00
if ( $line -> product_label ) {
$htmlforlines .= $line -> product_label ;
}
2021-02-26 21:17:52 +01:00
if ( $line -> product_label != $line -> desc ) {
if ( $line -> product_label && $line -> desc ) {
$htmlforlines .= '<br>' ;
}
2024-11-22 15:24:11 +01:00
$firstline = dolGetFirstLineOfText ( $line -> desc , getDolGlobalInt ( 'TAKEPOS_SHOW_N_FIRST_LINES' ));
2021-02-26 21:17:52 +01:00
if ( $firstline != $line -> desc ) {
2020-09-08 21:27:28 +02:00
$htmlforlines .= $form -> textwithpicto ( dolGetFirstLineOfText ( $line -> desc ), $line -> desc );
} else {
$htmlforlines .= $line -> desc ;
}
}
}
2021-02-26 21:17:52 +01:00
if ( ! empty ( $line -> array_options [ 'options_order_notes' ])) {
$htmlforlines .= " <br>( " . $line -> array_options [ 'options_order_notes' ] . " ) " ;
}
2021-07-08 12:17:32 +02:00
if ( ! empty ( $_SESSION [ " basiclayout " ]) && $_SESSION [ " basiclayout " ] == 1 ) {
2020-12-04 00:58:51 +01:00
$htmlforlines .= '</td><td class="right phonetable"><button type="button" onclick="SetQty(place, ' . $line -> rowid . ', ' . ( $line -> qty - 1 ) . ');" class="publicphonebutton2 phonered">-</button> <button type="button" onclick="SetQty(place, ' . $line -> rowid . ', ' . ( $line -> qty + 1 ) . ');" class="publicphonebutton2 phonegreen">+</button>' ;
}
2021-07-08 12:17:32 +02:00
if ( empty ( $_SESSION [ " basiclayout " ]) || $_SESSION [ " basiclayout " ] != 1 ) {
2020-01-01 21:54:47 +01:00
$moreinfo = '' ;
$moreinfo .= $langs -> transcountry ( " TotalHT " , $mysoc -> country_code ) . ': ' . price ( $line -> total_ht );
2021-02-26 21:17:52 +01:00
if ( $line -> vat_src_code ) {
$moreinfo .= '<br>' . $langs -> trans ( " VATCode " ) . ': ' . $line -> vat_src_code ;
}
2020-03-23 15:02:15 +01:00
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalVAT " , $mysoc -> country_code ) . ': ' . price ( $line -> total_tva );
2020-01-01 21:54:47 +01:00
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalLT1 " , $mysoc -> country_code ) . ': ' . price ( $line -> total_localtax1 );
$moreinfo .= '<br>' . $langs -> transcountry ( " TotalLT2 " , $mysoc -> country_code ) . ': ' . price ( $line -> total_localtax2 );
2022-11-07 11:28:08 +01:00
$moreinfo .= '<hr>' ;
$moreinfo .= $langs -> transcountry ( " TotalTTC " , $mysoc -> country_code ) . ': ' . price ( $line -> total_ttc );
2020-01-01 21:54:47 +01:00
//$moreinfo .= $langs->trans("TotalHT").': '.$line->total_ht;
2021-02-26 21:17:52 +01:00
if ( $line -> date_start || $line -> date_end ) {
$htmlforlines .= '<br><div class="clearboth nowraponall">' . get_date_range ( $line -> date_start , $line -> date_end ) . '</div>' ;
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</td>' ;
2022-05-06 11:34:05 +02:00
// complete line by hook
2024-03-07 20:16:48 +01:00
$parameters = array ( 'line' => $line );
$reshook = $hookmanager -> executeHooks ( 'completeTakePosInvoiceLine' , $parameters , $invoice , $action ); // Note that $action and $object may have been modified by some hooks
2023-12-04 13:53:48 +01:00
if ( $reshook < 0 ) {
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
}
2022-05-06 11:34:05 +02:00
$htmlforlines .= $hookmanager -> resPrint ;
2023-05-21 19:03:00 +02:00
if ( getDolGlobalInt ( " TAKEPOS_SHOW_SUBPRICE " )) {
2023-05-19 11:43:44 +02:00
$htmlforlines .= '<td class="right">' . price ( $line -> subprice ) . '</td>' ;
}
2024-09-23 01:59:14 +02:00
$htmlforlines .= '<td class="right">' . vatrate ( price2num ( $line -> remise_percent ), true ) . '</td>' ;
2020-09-20 23:29:59 +02:00
$htmlforlines .= '<td class="right">' ;
2023-10-15 18:41:39 +02:00
if ( isModEnabled ( 'stock' ) && $user -> hasRight ( 'stock' , 'mouvement' , 'lire' )) {
2020-09-20 23:29:59 +02:00
$constantforkey = 'CASHDESK_ID_WAREHOUSE' . $_SESSION [ " takeposterminal " ];
2023-11-27 12:08:48 +01:00
if ( getDolGlobalString ( $constantforkey ) && $line -> fk_product > 0 && ! getDolGlobalString ( 'TAKEPOS_HIDE_STOCK_ON_LINE' )) {
2020-12-04 00:58:51 +01:00
$sql = " SELECT e.rowid, e.ref, e.lieu, e.fk_parent, e.statut, ps.reel, ps.rowid as product_stock_id, p.pmp " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " entrepot as e, " ;
$sql .= " " . MAIN_DB_PREFIX . " product_stock as ps " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " product as p ON p.rowid = ps.fk_product " ;
$sql .= " WHERE ps.reel != 0 " ;
2023-10-09 15:44:57 +02:00
$sql .= " AND ps.fk_entrepot = " . (( int ) getDolGlobalString ( $constantforkey ));
2020-12-04 00:58:51 +01:00
$sql .= " AND e.entity IN ( " . getEntity ( 'stock' ) . " ) " ;
2021-08-23 19:33:24 +02:00
$sql .= " AND ps.fk_product = " . (( int ) $line -> fk_product );
2020-12-04 00:58:51 +01:00
$resql = $db -> query ( $sql );
if ( $resql ) {
2024-03-20 21:09:32 +01:00
$stock_real = 0 ;
2020-12-04 00:58:51 +01:00
$obj = $db -> fetch_object ( $resql );
2024-03-20 21:09:32 +01:00
if ( $obj ) {
$stock_real = price2num ( $obj -> reel , 'MS' );
}
2020-12-04 00:58:51 +01:00
$htmlforlines .= $line -> qty ;
2024-08-30 15:06:19 +02:00
$htmlforlines .= ' ' ;
$htmlforlines .= '<span class="opacitylow" title="' . $langs -> trans ( " Stock " ) . ' ' . price ( $stock_real , 1 , '' , 1 , 0 ) . '">' ;
$htmlforlines .= '(' ;
2021-02-26 21:17:52 +01:00
if ( $line -> qty && $line -> qty > $stock_real ) {
$htmlforlines .= '<span style="color: var(--amountremaintopaycolor)">' ;
}
2024-08-30 15:06:19 +02:00
$htmlforlines .= img_picto ( '' , 'stock' , 'class="pictofixedwidth"' ) . price ( $stock_real , 1 , '' , 1 , 0 );
2021-02-26 21:17:52 +01:00
if ( $line -> qty && $line -> qty > $stock_real ) {
$htmlforlines .= " </span> " ;
}
2024-08-30 15:06:19 +02:00
$htmlforlines .= ')' ;
$htmlforlines .= '</span>' ;
2020-12-04 00:58:51 +01:00
} else {
dol_print_error ( $db );
}
} else {
2020-09-24 00:06:02 +02:00
$htmlforlines .= $line -> qty ;
2020-09-20 23:29:59 +02:00
}
2020-12-04 00:58:51 +01:00
} else {
$htmlforlines .= $line -> qty ;
2020-09-20 23:29:59 +02:00
}
2020-12-04 00:58:51 +01:00
2020-09-20 23:29:59 +02:00
$htmlforlines .= '</td>' ;
2023-10-12 20:24:55 +02:00
if ( getDolGlobalInt ( 'TAKEPOS_SHOW_HT' )) {
2021-02-26 21:17:52 +01:00
$htmlforlines .= '<td class="right classfortooltip" title="' . $moreinfo . '">' ;
$htmlforlines .= price ( $line -> total_ht , 1 , '' , 1 , - 1 , - 1 , $conf -> currency );
2022-08-26 17:03:20 +02:00
if ( isModEnabled ( 'multicurrency' ) && ! empty ( $_SESSION [ " takeposcustomercurrency " ]) && $conf -> currency != $_SESSION [ " takeposcustomercurrency " ]) {
2021-02-26 21:17:52 +01:00
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php' ;
$multicurrency = new MultiCurrency ( $db );
$multicurrency -> fetch ( 0 , $_SESSION [ " takeposcustomercurrency " ]);
$htmlforlines .= '<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">(' . price ( $line -> total_ht * $multicurrency -> rate -> rate ) . ' ' . $_SESSION [ " takeposcustomercurrency " ] . ')</span>' ;
}
$htmlforlines .= '</td>' ;
}
2020-10-03 22:13:32 +02:00
$htmlforlines .= '<td class="right classfortooltip" title="' . $moreinfo . '">' ;
2020-10-04 14:42:16 +02:00
$htmlforlines .= price ( $line -> total_ttc , 1 , '' , 1 , - 1 , - 1 , $conf -> currency );
2022-08-26 17:03:20 +02:00
if ( isModEnabled ( 'multicurrency' ) && ! empty ( $_SESSION [ " takeposcustomercurrency " ]) && $conf -> currency != $_SESSION [ " takeposcustomercurrency " ]) {
2020-10-03 22:13:32 +02:00
//Only show customer currency if multicurrency module is enabled, if currency selected and if this currency selected is not the same as main currency
include_once DOL_DOCUMENT_ROOT . '/multicurrency/class/multicurrency.class.php' ;
$multicurrency = new MultiCurrency ( $db );
$multicurrency -> fetch ( 0 , $_SESSION [ " takeposcustomercurrency " ]);
2020-10-07 15:01:28 +02:00
$htmlforlines .= '<br><span id="linecolht-span-total" style="font-size:0.9em; font-style:italic;">(' . price ( $line -> total_ttc * $multicurrency -> rate -> rate ) . ' ' . $_SESSION [ " takeposcustomercurrency " ] . ')</span>' ;
2020-10-03 22:13:32 +02:00
}
$htmlforlines .= '</td>' ;
2019-05-26 16:44:17 +02:00
}
2019-11-12 00:15:34 +01:00
$htmlforlines .= '</tr>' . " \n " ;
2021-10-23 16:59:25 +02:00
$htmlforlines .= empty ( $htmlsupplements [ $line -> id ]) ? '' : $htmlsupplements [ $line -> id ];
2019-03-27 20:20:39 +01:00
2020-09-07 10:18:17 +02:00
print $htmlforlines ;
}
} else {
2024-01-07 12:49:43 +01:00
print '<tr class="drag drop oddeven"><td class="left"><span class="opacitymedium">' . $langs -> trans ( " Empty " ) . '</span></td><td></td>' ;
if ( empty ( $_SESSION [ " basiclayout " ]) || $_SESSION [ " basiclayout " ] != 1 ) {
print '<td></td><td></td>' ;
if ( getDolGlobalString ( 'TAKEPOS_SHOW_HT' )) {
print '<td></td>' ;
}
2021-02-26 21:17:52 +01:00
}
2021-02-24 15:48:15 +01:00
print '</tr>' ;
2020-09-07 10:18:17 +02:00
}
2020-05-21 15:05:19 +02:00
} else { // No invoice generated yet
2024-01-07 12:49:43 +01:00
print '<tr class="drag drop oddeven"><td class="left"><span class="opacitymedium">' . $langs -> trans ( " Empty " ) . '</span></td><td></td>' ;
if ( empty ( $_SESSION [ " basiclayout " ]) || $_SESSION [ " basiclayout " ] != 1 ) {
print '<td></td><td></td>' ;
if ( getDolGlobalString ( 'TAKEPOS_SHOW_HT' )) {
print '<td></td>' ;
}
2021-02-26 21:17:52 +01:00
}
print '</tr>' ;
2019-03-28 09:56:01 +01:00
}
2018-12-07 08:04:40 +01:00
2024-01-07 19:32:47 +01:00
if ( $usediv ) {
print '</div>' ;
} else {
print '</table>' ;
}
2018-12-07 08:04:40 +01:00
2023-11-27 12:08:48 +01:00
if (( $action == " valid " || $action == " history " ) && $invoice -> type != Facture :: TYPE_CREDIT_NOTE && ! getDolGlobalString ( 'TAKEPOS_NO_CREDITNOTE' )) {
2020-10-25 20:03:25 +01:00
print '<button id="buttonprint" type="button" onclick="ModalBox(\'ModalCreditNote\')">' . $langs -> trans ( 'CreateCreditNote' ) . '</button>' ;
2023-05-24 14:36:29 +02:00
if ( getDolGlobalInt ( 'TAKEPOS_PRINT_INVOICE_DOC_INSTEAD_OF_RECEIPT' )) {
2023-05-17 18:09:52 +02:00
print ' <a target="_blank" class="button" href="' . DOL_URL_ROOT . '/document.php?token=' . newToken () . '&modulepart=facture&file=' . $invoice -> ref . '/' . $invoice -> ref . '.pdf">Invoice</a>' ;
}
2020-10-25 20:03:25 +01:00
}
2020-01-01 21:54:47 +01:00
2021-02-26 21:17:52 +01:00
if ( $action == " search " ) {
2020-09-07 10:18:17 +02:00
print ' < center >
2023-07-31 21:44:03 +02:00
< input type = " text " id = " search " class = " input-nobottom " name = " search " onkeyup = " Search2( \ ' \ ', null); " style = " width: 80%; font-size: 150%; " placeholder = " '.dol_escape_htmltag( $langs->trans ('Search')).' " >
2018-09-28 13:31:41 +02:00
</ center > ' ;
}
2018-12-07 08:04:40 +01:00
2020-12-06 14:20:16 +01:00
print '</div>' ;
2022-08-22 00:04:04 +02:00
2022-08-22 01:56:19 +02:00
// llxFooter
if (( getDolGlobalString ( 'TAKEPOS_PHONE_BASIC_LAYOUT' ) == 1 && $conf -> browser -> layout == 'phone' ) || defined ( 'INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE' )) {
print '</body></html>' ;
2022-08-22 00:04:04 +02:00
}