From 0f23cef46c6235be07944eb9d3cc05d25c1c97d0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Jul 2016 18:59:36 +0200 Subject: [PATCH 1/7] Fix warning of the repair tool. --- .../class/fournisseur.commande.class.php | 2 +- htdocs/install/repair.php | 41 +++++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3c36bc611fd..19395db756c 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -313,7 +313,7 @@ class CommandeFournisseur extends CommonOrder $line->date_end = $this->db->jdate($objp->date_end); $line->fk_unit = $objp->fk_unit; - $this->special_line = $objp->special_line; + $this->special_code = $objp->special_code; $this->fk_parent_line = $objp->fk_parent_line; $this->rang = $objp->rang; diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index d6a26534586..d4679c9ac0c 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -73,6 +73,11 @@ $actiondone=1; print '

'.$langs->trans("Repair").'

'; +print 'Option restore_thirdparties_logos is '.(GETPOST('restore_thirdparties_logos')?GETPOST('restore_thirdparties_logos'):'0').'
'."\n"; +print 'Option clean_linked_elements is '.(GETPOST('clean_linked_elements')?GETPOST('clean_linked_elements'):'0').'
'."\n"; +print 'Option clean_orphelin_dir (1 or confirmed) is '.(GETPOST('clean_orphelin_dir')?GETPOST('clean_orphelin_dir'):'0').'
'."\n"; +print '
'; + print ''; $error=0; @@ -196,7 +201,8 @@ if ($ok) } -// sync_extrafields: Search list of fields declared and list of fields created into databases and create fields missing +// sync_extrafields: Search list of fields declared and list of fields created into databases, then create fields missing + if ($ok) { $extrafields=new ExtraFields($db); @@ -204,6 +210,7 @@ if ($ok) 'socpeople'=>'socpeople', 'commande'=>'commande', 'facture'=>'facture', 'commande_fournisseur'=>'commande_fournisseur', 'actioncomm'=>'actioncomm', 'adherent_type'=>'adherent_type','user'=>'user','projet'=>'projet', 'projet_task'=>'projet_task'); + print ''; foreach($listofmodulesextra as $tablename => $elementtype) { // Get list of fields @@ -292,6 +299,8 @@ if ($ok && GETPOST('restore_thirdparties_logos')) //$exts=array('gif','png','jpg'); $ext=''; + + print ''; //} } @@ -360,23 +371,24 @@ if ($ok && GETPOST('restore_thirdparties_logos')) // clean_linked_elements: Check and clean linked elements if ($ok && GETPOST('clean_linked_elements')) { + print ''; // propal => order - print "\n"; + print '\n"; // propal => invoice - print "\n"; + print '\n"; // order => invoice - print "\n"; + print '\n"; // order => shipping - print "\n"; + print '\n"; // shipping => delivery - print "\n"; + print '\n"; // order_supplier => invoice_supplier - print "\n"; + print '\n"; } @@ -399,11 +411,16 @@ if ($ok && GETPOST('clean_orphelin_dir')) if (empty($upload_dir)) continue; - print ''; + print ''; - $filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','(\.meta|_preview\.png)$','^temp$','^payments$','^CVS$','^thumbs$'),'',SORT_DESC,1); + $filearray=dol_dir_list($upload_dir,"files",1,'',array('^SPECIMEN\.pdf$','^\.','(\.meta|_preview\.png)$','^temp$','^payments$','^CVS$','^thumbs$'),'',SORT_DESC,1,true); // To show ref or specific information according to view to show (defined by $module) + if ($modulepart == 'company') + { + include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + $object_instance=new Societe($db); + } if ($modulepart == 'invoice') { include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; @@ -460,7 +477,7 @@ if ($ok && GETPOST('clean_orphelin_dir')) preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; } if ($modulepart == 'invoice_supplier') { - preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=$reg[1]; + preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg); $id=empty($reg[1])?'':$reg[1]; } if ($modulepart == 'propal') { preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg); $ref=$reg[1]; @@ -488,7 +505,7 @@ if ($ok && GETPOST('clean_orphelin_dir')) // Clean of orphelins directories are done into repair.php print '

Check fields into extra table structure match table of definition. If not add column into table

'; //foreach($exts as $ext) //{ $sql="SELECT s.rowid, s.nom as name, s.logo FROM ".MAIN_DB_PREFIX."societe as s ORDER BY s.nom"; @@ -353,6 +362,8 @@ if ($ok && GETPOST('restore_thirdparties_logos')) $ok=0; dol_print_error($db); } + + print '

Check table of linked elements and delete orphelins links
".checkLinkedElements('propal', 'commande')."
'.checkLinkedElements('propal', 'commande')."
".checkLinkedElements('propal', 'facture')."
'.checkLinkedElements('propal', 'facture')."
".checkLinkedElements('commande', 'facture')."
'.checkLinkedElements('commande', 'facture')."
".checkLinkedElements('commande', 'shipping')."
'.checkLinkedElements('commande', 'shipping')."
".checkLinkedElements('shipping', 'delivery')."
'.checkLinkedElements('shipping', 'delivery')."
".checkLinkedElements('order_supplier', 'invoice_supplier')."
'.checkLinkedElements('order_supplier', 'invoice_supplier')."
Clean orphelins files into files '.$upload_dir.'

Clean orphelins files into files '.$upload_dir.'
'; print 'Delete orphelins file '.$file['fullname'].'
'; - if (GETPOST('purge') == 2) + if (GETPOST('clean_orphelin_dir') == 'confirmed') { dol_delete_file($file['fullname'],1,1,1); dol_delete_dir(dirname($file['fullname']),1); @@ -512,7 +529,7 @@ if (empty($actiondone)) } -print '
'; +print ''; From a48c79b68b7da263ff8306a3cd087adb76d71912 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Jul 2016 23:02:25 +0200 Subject: [PATCH 2/7] Fix corrupted stock --- htdocs/install/repair.php | 102 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index d4679c9ac0c..e354b2a30da 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -76,6 +76,7 @@ print '

'.$langs->trans("Repair").'

'; print 'Option restore_thirdparties_logos is '.(GETPOST('restore_thirdparties_logos')?GETPOST('restore_thirdparties_logos'):'0').'
'."\n"; print 'Option clean_linked_elements is '.(GETPOST('clean_linked_elements')?GETPOST('clean_linked_elements'):'0').'
'."\n"; print 'Option clean_orphelin_dir (1 or confirmed) is '.(GETPOST('clean_orphelin_dir')?GETPOST('clean_orphelin_dir'):'0').'
'."\n"; +print 'Option clean_product_stock_batch (1 or confirmed) is '.(GETPOST('clean_product_stock_batch')?GETPOST('clean_product_stock_batch'):'0').'
'."\n"; print '
'; print ''; @@ -519,6 +520,107 @@ if ($ok && GETPOST('clean_orphelin_dir')) } } +// clean_linked_elements: Check and clean linked elements +if ($ok && GETPOST('clean_product_stock_batch')) +{ + print ''; + + $sql ="SELECT p.rowid, p.ref, p.tobatch, ps.rowid as psrowid, ps.fk_entrepot, ps.reel, SUM(pb.qty) as reelbatch"; + $sql.=" FROM ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product_batch as pb"; + $sql.=" WHERE p.rowid = ps.fk_product AND ps.rowid = pb.fk_product_stock"; + $sql.=" AND p.tobatch = 1"; + $sql.=" GROUP BY p.rowid, p.ref, p.tobatch, ps.rowid, ps.fk_entrepot, ps.reel"; + $sql.=" HAVING reel != SUM(pb.qty)"; + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + + if ($num) + { + $i = 0; + while ($i < $num) + { + $obj=$db->fetch_object($resql); + print ''; + + $i++; + } + } + } + else + { + dol_print_error($db); + } + + +} + + + + + print '

Clean table product_batch
'.$obj->rowid.'-'.$obj->ref.'-'.$obj->fk_entrepot.' -> '.$obj->psrowid.': '.$obj->reel.' != '.$obj->reelbatch; + + // Fix + if ($obj->reel > $obj->reelbatch) + { + $methodtofix='updatestock'; + + if ($methodtofix == 'updatebatch') + { + // Method 1 + print ' -> Insert qty '.($obj->reel - $obj->reelbatch).' with lot 000000 linked to fk_product_stock='.$obj->psrowid; + if (GETPOST('clean_product_stock_batch') == 'confirmed') + { + $sql2 ="INSERT INTO ".MAIN_DB_PREFIX."product_batch(fk_product_stock, batch, qty)"; + $sql2.="VALUES(".$obj->psrowid.", '000000', ".($obj->reel - $obj->reelbatch).")"; + $resql2=$db->query($sql2); + if (! $resql2) + { + // TODO If it fails, we must make update + //$sql2 ="UPDATE ".MAIN_DB_PREFIX."product_batch"; + //$sql2.=" SET ".$obj->psrowid.", '000000', ".($obj->reel - $obj->reelbatch).")"; + //$sql2.=" WHERE fk_product_stock = ".$obj->psrowid" + } + } + } + if ($methodtofix == 'updatestock') + { + // Method 2 + print ' -> Update qty of stock with qty = '.$obj->reelbatch.' for ps.rowid = '.$obj->psrowid; + if (GETPOST('clean_product_stock_batch') == 'confirmed') + { + $error=0; + + $db->begin(); + + $sql2 ="UPDATE ".MAIN_DB_PREFIX."product_stock"; + $sql2.=" SET reel = ".$obj->reelbatch." WHERE rowid = ".$obj->psrowid; + $resql2=$db->query($sql2); + if ($resql2) + { + // We update product stock, so we must update product.stock too. + $sql3='UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid)'; + $resql3=$db->query($sql3); + if (! $resql3) + { + $error++; + dol_print_error($db); + } + } + else + { + $error++; + dol_print_error($db); + } + + if (!$error) $db->commit(); + else $db->rollback(); + } + } + } + + print'
'; From 47d7ac8031ad1d8cc5d17a1081ed1433c51cb23a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 8 Jul 2016 23:11:55 +0200 Subject: [PATCH 3/7] Fix the repair tool to correct corrupted stock for batch numbers --- htdocs/install/repair.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/repair.php b/htdocs/install/repair.php index e354b2a30da..952c22baa44 100644 --- a/htdocs/install/repair.php +++ b/htdocs/install/repair.php @@ -545,7 +545,7 @@ if ($ok && GETPOST('clean_product_stock_batch')) print '
'.$obj->rowid.'-'.$obj->ref.'-'.$obj->fk_entrepot.' -> '.$obj->psrowid.': '.$obj->reel.' != '.$obj->reelbatch; // Fix - if ($obj->reel > $obj->reelbatch) + if ($obj->reel != $obj->reelbatch) { $methodtofix='updatestock'; From d01796a2149c2c45e28520da7594a10744902868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sat, 9 Jul 2016 14:31:41 +0200 Subject: [PATCH 4/7] FIX #5470 User of expense report in bank transactions page is not correct --- htdocs/expensereport/payment/payment.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/expensereport/payment/payment.php b/htdocs/expensereport/payment/payment.php index b7d40b2e65b..c4351e4d038 100644 --- a/htdocs/expensereport/payment/payment.php +++ b/htdocs/expensereport/payment/payment.php @@ -57,6 +57,9 @@ if ($action == 'add_payment') exit; } + $expensereport = new ExpenseReport($db); + $expensereport->fetch($chid); + $datepaid = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); if (! $_POST["fk_typepayment"] > 0) @@ -85,8 +88,7 @@ if ($action == 'add_payment') { if (substr($key,0,7) == 'amount_') { - $other_chid = substr($key,7); - $amounts[$other_chid] = price2num($_POST[$key]); + $amounts[$expensereport->fk_user_author] = price2num($_POST[$key]); $total += price2num($_POST[$key]); } } From 0367cee671b5c95b36f08f1e2357d7971bc313b4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 11 Jul 2016 11:34:11 +0200 Subject: [PATCH 5/7] FIX We must take the last recent defined price when using price level --- htdocs/core/class/html.form.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 64ec3d4afdd..c4273a779a9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1896,8 +1896,8 @@ class Form $sql.= " WHERE fk_product='".$objp->rowid."'"; $sql.= " AND entity IN (".getEntity('productprice', 1).")"; $sql.= " AND price_level=".$price_level; - $sql.= " ORDER BY date_price, rowid"; - $sql.= " DESC LIMIT 1"; + $sql.= " ORDER BY date_price DESC, rowid DESC"; + $sql.= " LIMIT 1"; dol_syslog(get_class($this).'::constructProductListOption search price for level '.$price_level.'', LOG_DEBUG); $result2 = $this->db->query($sql); From 572b2fdec7efaa8bb6d7c92ad0a2c5808ee5ec86 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Tue, 12 Jul 2016 15:01:43 +0200 Subject: [PATCH 6/7] FIX dasboard wrong for late invoice --- htdocs/compta/facture/class/facture.class.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 27432d7c399..33d6e23c6b3 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3212,7 +3212,7 @@ class Facture extends CommonInvoice $clause = " WHERE"; - $sql = "SELECT f.rowid, f.date_lim_reglement as datefin"; + $sql = "SELECT f.rowid, f.date_lim_reglement as datefin,f.fk_statut"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) { @@ -3242,6 +3242,7 @@ class Facture extends CommonInvoice while ($obj=$this->db->fetch_object($resql)) { $generic_facture->date_lim_reglement = $this->db->jdate($obj->datefin); + $generic_facture->statut = $obj->fk_statut; $response->nbtodo++; @@ -3249,7 +3250,7 @@ class Facture extends CommonInvoice $response->nbtodolate++; } } - + return $response; } else @@ -3727,7 +3728,7 @@ class Facture extends CommonInvoice global $conf; $now = dol_now(); - + // Paid invoices have status STATUS_CLOSED if ($this->statut != Facture::STATUS_VALIDATED) return false; From f972b15f5fec4b431fb0566a8355bfca34748716 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 12 Jul 2016 19:22:14 +0200 Subject: [PATCH 7/7] FIX #5068 --- htdocs/product/card.php | 44 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index c269e560a4c..59ccdb79a1f 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -609,8 +609,20 @@ if (empty($reshook)) $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); } } - + if (GETPOST('propalid') > 0) { + // Define cost price for margin calculation + $buyprice=0; + if (($result = $propal->defineBuyPrice($pu_ht, GETPOST('remise_percent'), $object->id)) < 0) + { + dol_syslog($langs->trans('FailedToGetCostPrice')); + setEventMessage($langs->trans('FailedToGetCostPrice'), 'errors'); + } + else + { + $buyprice = $result; + } + $result = $propal->addline( $desc, $pu_ht, @@ -628,7 +640,7 @@ if (empty($reshook)) 0, 0, 0, - 0, + $buyprice, '', '', '', @@ -642,6 +654,18 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorUnknown") . ": $result", null, 'errors'); } elseif (GETPOST('commandeid') > 0) { + // Define cost price for margin calculation + $buyprice=0; + if (($result = $commande->defineBuyPrice($pu_ht, GETPOST('remise_percent'), $object->id)) < 0) + { + dol_syslog($langs->trans('FailedToGetCostPrice')); + setEventMessage($langs->trans('FailedToGetCostPrice'), 'errors'); + } + else + { + $buyprice = $result; + } + $result = $commande->addline( $desc, $pu_ht, @@ -662,7 +686,7 @@ if (empty($reshook)) 0, 0, null, - 0, + $buyprice, '', 0, $object->fk_unit @@ -673,6 +697,18 @@ if (empty($reshook)) exit; } } elseif (GETPOST('factureid') > 0) { + // Define cost price for margin calculation + $buyprice=0; + if (($result = $facture->defineBuyPrice($pu_ht, GETPOST('remise_percent'), $object->id)) < 0) + { + dol_syslog($langs->trans('FailedToGetCostPrice')); + setEventMessage($langs->trans('FailedToGetCostPrice'), 'errors'); + } + else + { + $buyprice = $result; + } + $result = $facture->addline( $desc, $pu_ht, @@ -696,7 +732,7 @@ if (empty($reshook)) 0, 0, null, - 0, + $buyprice, '', 0, 100,