浏览代码

Merge branch '18.0' of git@github.com:Dolibarr/dolibarr.git into 19.0

Conflicts:
	htdocs/core/class/html.formsetup.class.php
	htdocs/takepos/index.php
Laurent Destailleur 1 年之前
父节点
当前提交
b658bde88a

+ 1 - 1
htdocs/compta/facture/class/facture.class.php

@@ -4031,7 +4031,7 @@ class Facture extends CommonInvoice
 				return -2;
 			}
 		} else {
-			$this->errors[]='status of invoice must be Draft to allow use of ->addline()';
+			$this->errors[] = 'status of invoice must be Draft to allow use of ->addline()';
 			dol_syslog(get_class($this)."::addline status of invoice must be Draft to allow use of ->addline()", LOG_ERR);
 			return -3;
 		}

+ 12 - 4
htdocs/core/class/html.formsetup.class.php

@@ -26,6 +26,9 @@ class FormSetup
 	 */
 	public $db;
 
+	/** @var int */
+	public $entity;
+
 	/** @var FormSetupItem[]  */
 	public $items = array();
 
@@ -90,7 +93,8 @@ class FormSetup
 	 */
 	public function __construct($db, $outputLangs = null)
 	{
-		global $langs;
+		global $conf, $langs;
+
 		$this->db = $db;
 
 		$this->form = new Form($this->db);
@@ -99,6 +103,8 @@ class FormSetup
 		$this->formHiddenInputs['token'] = newToken();
 		$this->formHiddenInputs['action'] = 'update';
 
+		$this->entity = (is_null($this->entity) ? $conf->entity : $this->entity);
+
 		if ($outputLangs) {
 			$this->langs = $outputLangs;
 		} else {
@@ -454,6 +460,8 @@ class FormSetup
 	{
 		$item = new FormSetupItem($confKey);
 
+		$item->entity = $this->entity;
+
 		// set item rank if not defined as last item
 		if (empty($item->rank)) {
 			$item->rank = $this->getCurentItemMaxRank() + 1;
@@ -646,7 +654,7 @@ class FormSetupItem
 	/**
 	 * Constructor
 	 *
-	 * @param string $confKey the conf key used in database
+	 * @param string	$confKey	the conf key used in database
 	 */
 	public function __construct($confKey)
 	{
@@ -660,7 +668,7 @@ class FormSetupItem
 		}
 
 		$this->langs = $langs;
-		$this->entity = $conf->entity;
+		$this->entity = (is_null($this->entity) ? $conf->entity : ((int) $this->entity));
 
 		$this->confKey = $confKey;
 		$this->loadValueFromConf();
@@ -1119,7 +1127,7 @@ class FormSetupItem
 			$out.=  $this->generateOutputFieldColor();
 		} elseif ($this->type == 'yesno') {
 			if (!empty($conf->use_javascript_ajax)) {
-				$out.= ajax_constantonoff($this->confKey);
+				$out.= ajax_constantonoff($this->confKey, array(), $this->entity); // TODO possibility to add $input parameter
 			} else {
 				if ($this->fieldValue == 1) {
 					$out.= $langs->trans('yes');

+ 7 - 4
htdocs/takepos/freezone.php

@@ -51,6 +51,8 @@ $langs->loadLangs(array("bills", "cashdesk"));
 
 $place = (GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'); // $place is id of table for Bar or Restaurant
 
+$invoiceid = GETPOST('invoiceid', 'int');
+
 $idline = GETPOST('idline', 'int');
 $action = GETPOST('action', 'aZ09');
 
@@ -60,12 +62,13 @@ if (!$user->hasRight('takepos', 'run')) {
 
 // get invoice
 $invoice = new Facture($db);
-if ($place > 0) {
-	$invoice->fetch($place);
+if ($invoiceid > 0) {
+	$invoice->fetch($invoiceid);
 } else {
 	$invoice->fetch('', '(PROV-POS'.$_SESSION['takeposterminal'].'-'.$place.')');
 }
 
+
 // get default vat rate
 $constforcompanyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION['takeposterminal'];
 $soc = new Societe($db);
@@ -108,8 +111,8 @@ top_htmlhead('', '', 0, 0, $arrayofjs, $arrayofcss);
 	 * Save (validate)
 	 */
 	function Save() {
-		console.log("We click so we call page invoice.php with place=<?php echo $place; ?> tva_tx="+vatRate);
-		parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&place=<?php echo $place; ?>&number="+$('#number').val()+"&tva_tx="+vatRate, {desc:$('#desc').val()});
+		console.log("We click so we call page invoice.php with invoiceid=<?php echo $invoiceid; ?>, place=<?php echo $place; ?>, amount="+$("#number").val()+", tva_tx="+vatRate);
+		parent.$("#poslines").load("invoice.php?action=freezone&token=<?php echo newToken(); ?>&invoiceid=<?php echo $invoiceid; ?>&place=<?php echo $place; ?>&number="+$("#number").val()+"&tva_tx="+vatRate, {desc:$("#desc").val()});
 		parent.$.colorbox.close();
 	}
 

+ 9 - 6
htdocs/takepos/index.php

@@ -531,11 +531,12 @@ function ClickProduct(position, qty = 1) {
 	}
 	else{
 		console.log($('#prodiv4').data('rowid'));
+		invoiceid = $("#invoiceid").val();
 		idproduct=$('#prodiv'+position).data('rowid');
-		console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty);
+		console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty+" invoicdeid="+invoiceid);
 		if (idproduct=="") return;
 		// Call page invoice.php to generate the section with product lines
-		$("#poslines").load("invoice.php?action=addline&token=<?php echo newToken() ?>&place="+place+"&idproduct="+idproduct+"&qty="+qty, function() {
+		$("#poslines").load("invoice.php?action=addline&token=<?php echo newToken() ?>&place="+place+"&idproduct="+idproduct+"&qty="+qty+"&invoiceid="+invoiceid, function() {
 			<?php if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
 					echo "CustomerDisplay();";
 			}?>
@@ -555,8 +556,9 @@ function ChangeThirdparty(idcustomer) {
 }
 
 function deleteline() {
-	console.log("Delete line");
-	$("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline, function() {
+	invoiceid = $("#invoiceid").val();
+	console.log("Delete line invoiceid="+invoiceid);
+	$("#poslines").load("invoice.php?action=deleteline&token=<?php echo newToken(); ?>&place="+place+"&idline="+selectedline+"&invoiceid="+invoiceid, function() {
 		//$('#poslines').scrollTop($('#poslines')[0].scrollHeight);
 	});
 	ClearSearch();
@@ -602,8 +604,9 @@ function Floors() {
 }
 
 function FreeZone() {
-	console.log("Open box to enter a free product");
-	$.colorbox({href:"freezone.php?action=freezone&token=<?php echo newToken(); ?>&place="+place, width:"80%", height:"40%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone"); ?>"});
+	invoiceid = $("#invoiceid").val();
+	console.log("Open box to enter a free product on invoiceid="+invoiceid);
+	$.colorbox({href:"freezone.php?action=freezone&token=<?php echo newToken(); ?>&place="+place+"&invoiceid="+invoiceid, width:"80%", height:"40%", transition:"none", iframe:"true", title:"<?php echo $langs->trans("FreeZone"); ?>"});
 }
 
 function TakeposOrderNotes() {

+ 6 - 1
htdocs/takepos/invoice.php

@@ -513,6 +513,7 @@ if (empty($reshook)) {
 		}
 	}
 
+	// If we add a line by click on product (invoice exists here because it was created juste before if it didn't exists)
 	if ($action == "addline" && ($user->hasRight('takepos', 'run') || defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE'))) {
 		$prod = new Product($db);
 		$prod->fetch($idproduct);
@@ -703,6 +704,7 @@ if (empty($reshook)) {
 		$invoice->fetch($placeid);
 	}
 
+	// If we add a line by submitting freezone form (invoice exists here because it was created juste before if it didn't exists)
 	if ($action == "freezone" && $user->hasRight('takepos', 'run')) {
 		$customer = new Societe($db);
 		$customer->fetch($invoice->socid);
@@ -720,7 +722,10 @@ if (empty($reshook)) {
 		$localtax1_tx = get_localtax($tva_tx, 1, $customer, $mysoc, $tva_npr);
 		$localtax2_tx = get_localtax($tva_tx, 2, $customer, $mysoc, $tva_npr);
 
-		$invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 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, null, '', '', 0, 100, '', null, 0);
+		$res = $invoice->addline($desc, $number, 1, $tva_tx, $localtax1_tx, $localtax2_tx, 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, null, '', '', 0, 100, '', null, 0);
+		if ($res < 0) {
+			dol_htmloutput_errors($invoice->error, $invoice->errors, 1);
+		}
 		$invoice->fetch($placeid);
 	}