diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index fce70e56051..4df2c68243a 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -43,7 +43,7 @@ if ($user->societe_id > 0) accessforbidden(); if (! $user->rights->accounting->ventilation->read) accessforbidden(); - + // Filter $year = $_GET["year"]; if ($year == 0) { @@ -57,17 +57,17 @@ if ($year == 0) { // Validate History $action = GETPOST('action'); if ($action == 'validatehistory') { - + $error = 0; $db->begin(); - + if ($db->type == 'pgsql') { - $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid"; + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet"; + $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facturedet.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; - $sql1 .= " AND fd.fk_code_ventilation = 0"; + $sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid"; @@ -75,9 +75,9 @@ if ($action == 'validatehistory') { $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; $sql1 .= " AND fd.fk_code_ventilation = 0"; } - + dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG); - + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -90,7 +90,7 @@ if ($action == 'validatehistory') { } elseif ($action == 'fixaccountancycode') { $error = 0; $db->begin(); - + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; $sql1 .= " SET fd.fk_code_ventilation = 0"; $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN '; @@ -98,9 +98,9 @@ if ($action == 'validatehistory') { $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); - + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -113,15 +113,15 @@ if ($action == 'validatehistory') { } elseif ($action == 'cleanaccountancycode') { $error = 0; $db->begin(); - + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; $sql1 .= " SET fd.fk_code_ventilation = 0"; $sql1 .= " WHERE fd.fk_facture IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f"; $sql1 .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; $sql1 .= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "')"; - + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); - + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -196,11 +196,10 @@ $sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label"; dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { - $i = 0; $num = $db->num_rows($resql); - - while ( $i < $num ) { - $row = $db->fetch_row($resql); + + while ( $row = $db->fetch_row($resql)) { + $var = ! $var; print '' . length_accountg($row[0]) . ''; print '' . $row[1] . ''; @@ -210,7 +209,6 @@ if ($resql) { print '' . price($row[13]) . ''; print '' . price($row[14]) . ''; print ''; - $i ++; } $db->free($resql); } else { @@ -245,10 +243,8 @@ $resql = $db->query($sql); if ($resql) { $i = 0; $num = $db->num_rows($resql); - - while ( $i < $num ) { - $row = $db->fetch_row($resql); - + + while ($row = $db->fetch_row($resql)) { print '' . $row[0] . ''; for($i = 1; $i <= 12; $i ++) { print '' . price($row[$i]) . ''; @@ -271,37 +267,34 @@ if (! empty($conf->margin->enabled)) { print '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . ''; } print '' . $langs->trans("Total") . ''; - - $sql = "SELECT '" . $langs->trans("Vide") . "' AS 'Marge',"; + + $sql = "SELECT '" . $langs->trans("Vide") . "' AS marge,"; for($i = 1; $i <= 12; $i ++) { $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } - $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as 'Total'"; + $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; - + if (! empty($conf->multicompany->enabled)) { $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")"; } - + dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql); $resql = $db->query($sql); if ($resql) { - $i = 0; $num = $db->num_rows($resql); - - while ( $i < $num ) { - $row = $db->fetch_row($resql); - + + while ($row = $db->fetch_row($resql)) { + print '' . $row[0] . ''; for($i = 1; $i <= 12; $i ++) { print '' . price($row[$i]) . ''; } print '' . price($row[13]) . ''; print ''; - $i ++; } $db->free($resql); } else { diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 167f558d830..0c1a4d1eb6b 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -185,7 +185,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON p.accountancy_code_sell = aa.account_number"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version"; $sql .= " WHERE f.fk_statut > 0"; -$sql .= " AND fk_code_ventilation <= 0"; +$sql .= " AND l.fk_code_ventilation <= 0"; $sql .= " AND product_type <= 2"; $sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='')"; @@ -307,6 +307,7 @@ if ($result) { // Ref Invoice $facture_static->ref = $objp->facnumber; $facture_static->id = $objp->facid; + $facture_static->type = $objp->ftype; print '' . $facture_static->getNomUrl(1) . ''; // Ref Product $product_static->ref = $objp->product_ref; diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 5e87985ce61..9dd5bd1e1d7 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -41,7 +41,7 @@ if ($user->societe_id > 0) accessforbidden(); if (! $user->rights->accounting->ventilation->read) accessforbidden(); - + // Filter $year = $_GET["year"]; if ($year == 0) { @@ -55,17 +55,17 @@ if ($year == 0) { // Validate History $action = GETPOST('action'); if ($action == 'validatehistory') { - + $error = 0; $db->begin(); - + if ($db->type == 'pgsql') { - $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; - $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid"; + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det"; + $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " FROM " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; + $sql1 .= " WHERE " . MAIN_DB_PREFIX . "facture_fourn_det.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number"; - $sql1 .= " AND fd.fk_code_ventilation = 0"; + $sql1 .= " AND " . MAIN_DB_PREFIX . "facture_fourn_det.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid"; @@ -73,7 +73,7 @@ if ($action == 'validatehistory') { $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number"; $sql1 .= " AND fd.fk_code_ventilation = 0"; } - + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -86,7 +86,7 @@ if ($action == 'validatehistory') { } elseif ($action == 'fixaccountancycode') { $error = 0; $db->begin(); - + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; $sql1 .= " SET fd.fk_code_ventilation = 0"; $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN '; @@ -94,9 +94,9 @@ if ($action == 'validatehistory') { $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; $sql1 .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; $sql1 .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; - + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); - + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -109,15 +109,15 @@ if ($action == 'validatehistory') { } elseif ($action == 'cleanaccountancycode') { $error = 0; $db->begin(); - + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; $sql1 .= " SET fd.fk_code_ventilation = 0"; $sql1 .= " WHERE fd.fk_facture_fourn IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; $sql1 .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; $sql1 .= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "')"; - + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); - + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -154,35 +154,17 @@ $var = true; print ''; print ''; print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; +for($i = 1; $i <= 12; $i ++) { + print ''; +} print ''; -$sql = "SELECT IF(aa.account_number IS NULL, 'Non pointe', aa.account_number) AS 'code comptable',"; -$sql .= " IF(aa.label IS NULL, 'Non pointe', aa.label) AS 'Intitulé',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=1,ffd.total_ht,0)),2) AS 'Janvier',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=2,ffd.total_ht,0)),2) AS 'Fevrier',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=3,ffd.total_ht,0)),2) AS 'Mars',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=4,ffd.total_ht,0)),2) AS 'Avril',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=5,ffd.total_ht,0)),2) AS 'Mai',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=6,ffd.total_ht,0)),2) AS 'Juin',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=7,ffd.total_ht,0)),2) AS 'Juillet',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=8,ffd.total_ht,0)),2) AS 'Aout',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=9,ffd.total_ht,0)),2) AS 'Septembre',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=10,ffd.total_ht,0)),2) AS 'Octobre',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=11,ffd.total_ht,0)),2) AS 'Novembre',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=12,ffd.total_ht,0)),2) AS 'Decembre',"; -$sql .= " ROUND(SUM(ffd.total_ht),2) as 'Total'"; +$sql = "SELECT ".$db->ifsql('aa.account_number IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.account_number') ." AS codecomptable,"; +$sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.label') . " AS intitule,"; +for($i = 1; $i <= 12; $i ++) { + $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; +} +$sql .= " ROUND(SUM(ffd.total_ht),2) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation"; @@ -194,35 +176,24 @@ if (! empty($conf->multicompany->enabled)) { $sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 1) . ")"; } -$sql .= " GROUP BY ffd.fk_code_ventilation"; +$sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label"; dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); $resql = $db->query($sql); if ($resql) { - $i = 0; $num = $db->num_rows($resql); - - while ( $i < $num ) { - - $row = $db->fetch_row($resql); + + while ( $row = $db->fetch_row($resql)) { + $var = ! $var; print ''; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + for($i = 2; $i <= 12; $i ++) { + print ''; + } print ''; print ''; print ''; - $i ++; } $db->free($resql); } else { @@ -233,34 +204,16 @@ print "
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans("JanuaryMin") . '' . $langs->trans("FebruaryMin") . '' . $langs->trans("MarchMin") . '' . $langs->trans("AprilMin") . '' . $langs->trans("MayMin") . '' . $langs->trans("JuneMin") . '' . $langs->trans("JulyMin") . '' . $langs->trans("AugustMin") . '' . $langs->trans("SeptemberMin") . '' . $langs->trans("OctoberMin") . '' . $langs->trans("NovemberMin") . '' . $langs->trans("DecemberMin") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . length_accountg($row[0]) . '' . $row[1] . '' . price($row[2]) . '' . price($row[3]) . '' . price($row[4]) . '' . price($row[5]) . '' . price($row[6]) . '' . price($row[7]) . '' . price($row[8]) . '' . price($row[9]) . '' . price($row[10]) . '' . price($row[11]) . '' . price($row[12]) . '' . price($row[$i]) . '' . price($row[13]) . '' . price($row[14]) . '
\n"; print "
\n"; print ''; print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; +for($i = 1; $i <= 12; $i ++) { + print ''; +} print ''; -$sql = "SELECT '" . $langs->trans("CAHTF") . "' AS 'Total',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=1,ffd.total_ht,0)),2) AS 'Janvier',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=2,ffd.total_ht,0)),2) AS 'Fevrier',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=3,ffd.total_ht,0)),2) AS 'Mars',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=4,ffd.total_ht,0)),2) AS 'Avril',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=5,ffd.total_ht,0)),2) AS 'Mai',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=6,ffd.total_ht,0)),2) AS 'Juin',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=7,ffd.total_ht,0)),2) AS 'Juillet',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=8,ffd.total_ht,0)),2) AS 'Aout',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=9,ffd.total_ht,0)),2) AS 'Septembre',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=10,ffd.total_ht,0)),2) AS 'Octobre',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=11,ffd.total_ht,0)),2) AS 'Novembre',"; -$sql .= " ROUND(SUM(IF(MONTH(ff.datef)=12,ffd.total_ht,0)),2) AS 'Decembre',"; -$sql .= " ROUND(SUM(ffd.total_ht),2) as 'Total'"; +$sql = "SELECT '" . $langs->trans("CAHTF") . "' AS label,"; +for($i = 1; $i <= 12; $i ++) { + $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; +} +$sql .= " ROUND(SUM(ffd.total_ht),2) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; @@ -274,31 +227,19 @@ if (! empty($conf->multicompany->enabled)) { dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); $resql = $db->query($sql); if ($resql) { - $i = 0; $num = $db->num_rows($resql); - - while ( $i < $num ) { - $row = $db->fetch_row($resql); - + + while ( $row = $db->fetch_row($resql)) { + + print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + for($i = 1; $i <= 12; $i ++) { + print ''; + } print ''; print ''; - - $i ++; } - + $db->free($resql); } else { print $db->lasterror(); // Show last sql error diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index a663d683fe3..056466706a1 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -158,6 +158,8 @@ OptionModeProductSell=Mode sales OptionModeProductBuy=Mode purchases OptionModeProductSellDesc=Show all products with no accounting account defined for sales. OptionModeProductBuyDesc=Show all products with no accounting account defined for purchases. +CleanFixHistory=Remove accountancy code from lines that not exists into charts of account +CleanHistory=Reset all accountancy for selected year ## Dictionary Range=Range of accounting account diff --git a/htdocs/langs/en_US/supplier_proposal.lang b/htdocs/langs/en_US/supplier_proposal.lang index 909a4d713c1..e39a69a3dbe 100644 --- a/htdocs/langs/en_US/supplier_proposal.lang +++ b/htdocs/langs/en_US/supplier_proposal.lang @@ -47,6 +47,7 @@ DefaultModelSupplierProposalCreate=Default model creation DefaultModelSupplierProposalToBill=Default template when closing a price request (accepted) DefaultModelSupplierProposalClosed=Default template when closing a price request (refused) ListOfSupplierProposal=List of supplier proposal requests +ListSupplierProposalsAssociatedProject=List of supplier proposals associated with project SupplierProposalsToClose=Supplier proposals to close SupplierProposalsToProcess=Supplier proposals to process LastSupplierProposals=Last price requests diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index 81a7e7b800d..7f331251d22 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -45,8 +45,9 @@ $sref=GETPOST("sref"); $snom=GETPOST("snom"); $sall=GETPOST("sall"); $type=GETPOST("type","int"); -$sbarcode=GETPOST("sbarcode"); -$search_batch=GETPOST('search_batch'); +$sbarcode=GETPOST("sbarcode",'alpha'); +$search_warehouse=GETPOST('search_warehouse','alpha'); +$search_batch=GETPOST('search_batch','alpha'); $catid=GETPOST('catid','int'); $toolowstock=GETPOST('toolowstock'); $tosell = GETPOST("tosell"); @@ -85,6 +86,8 @@ if (! empty($_POST["button_removefilter_x"])) $type=""; $catid=''; $toolowstock=''; + $search_batch=''; + $search_warehouse=''; } @@ -110,14 +113,16 @@ $title=$langs->trans("ProductsAndServices"); $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,'; $sql.= ' p.fk_product_type, p.tms as datem,'; $sql.= ' p.duration, p.tosell as statut, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tobatch,'; -$sql.= ' s.fk_entrepot,'; +$sql.= ' ps.fk_entrepot,'; +$sql.= ' e.label as warehouse_label,'; $sql.= ' pb.batch, pb.eatby as oldeatby, pb.sellby as oldsellby,'; $sql.= ' pl.eatby, pl.sellby,'; $sql.= ' SUM(pb.qty) as stock_physique, COUNT(pb.rowid) as nbinbatchtable'; $sql.= ' FROM '.MAIN_DB_PREFIX.'product as p'; -$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as s on p.rowid = s.fk_product'; -$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = s.rowid'; -$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_stock as ps on p.rowid = ps.fk_product'; // Detail for each warehouse +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot as e on ps.fk_entrepot = e.rowid'; // Link on unique key +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_batch as pb on pb.fk_product_stock = ps.rowid'; // Detail for each lot on each warehouse +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_lot as pl on pl.fk_product = p.rowid AND pl.batch = pb.batch'; // Link on unique key // We'll need this table joined to the select in order to filter by categ if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_product as cp"; $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; @@ -138,45 +143,26 @@ if (dol_strlen($type)) $sql.= " AND p.fk_product_type <> '1'"; } } -if ($sref) $sql.= " AND p.ref LIKE '%".$sref."%'"; -if ($sbarcode) $sql.= " AND p.barcode LIKE '%".$sbarcode."%'"; -if ($snom) $sql.= " AND p.label LIKE '%".$db->escape($snom)."%'"; -if (! empty($tosell)) -{ - $sql.= " AND p.tosell = ".$tosell; -} -if (! empty($tobuy)) -{ - $sql.= " AND p.tobuy = ".$tobuy; -} -if (! empty($canvas)) -{ - $sql.= " AND p.canvas = '".$db->escape($canvas)."'"; -} -if($catid) -{ - $sql.= " AND cp.fk_categorie = ".$catid; -} -if ($fourn_id > 0) -{ - $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; -} +if ($sref) $sql.= natural_search("p.ref", $sref); +if ($sbarcode) $sql.= natural_search("p.barcode", $sbarcode); +if ($snom) $sql.= natural_search("p.label", $snom); +if (! empty($tosell)) $sql.= " AND p.tosell = ".$tosell; +if (! empty($tobuy)) $sql.= " AND p.tobuy = ".$tobuy; +if (! empty($canvas)) $sql.= " AND p.canvas = '".$db->escape($canvas)."'"; +if($catid) $sql.= " AND cp.fk_categorie = ".$catid; +if ($fourn_id > 0) $sql.= " AND p.rowid = pf.fk_product AND pf.fk_soc = ".$fourn_id; // Insert categ filter -if ($search_categ) -{ - $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); -} -if ($search_batch) -{ - $sql .= " AND pb.batch LIKE '%".$db->escape($search_batch)."%'"; -} +if ($search_categ) $sql .= " AND cp.fk_categorie = ".$db->escape($search_categ); +if ($search_warehouse) $sql .= natural_search("e.label", $search_warehouse); +if ($search_batch) $sql .= natural_search("pb.batch", $search_batch); $sql.= " GROUP BY p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,"; $sql.= " p.fk_product_type, p.tms,"; $sql.= " p.duration, p.tosell, p.tobuy, p.seuil_stock_alerte, p.desiredstock, p.stock, p.tobatch,"; -$sql.= " s.fk_entrepot,"; +$sql.= " ps.fk_entrepot,"; +$sql.= " e.label,"; $sql.= " pb.batch, pb.eatby, pb.sellby,"; $sql.= " pl.eatby, pl.sellby"; -if ($toolowstock) $sql.= " HAVING SUM(".$db->ifsql('s.reel IS NULL', '0', 's.reel').") < p.seuil_stock_alerte"; // Not used yet +if ($toolowstock) $sql.= " HAVING SUM(".$db->ifsql('ps.reel IS NULL', '0', 'ps.reel').") < p.seuil_stock_alerte"; // Not used yet $sql.= $db->order($sortfield,$sortorder); $sql.= $db->plimit($limit + 1, $offset); $resql = $db->query($sql); @@ -262,7 +248,7 @@ if ($resql) print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.ref",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"], "p.label",$param,"","",$sortfield,$sortorder); if (! empty($conf->service->enabled) && $type == 1) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Warehouse"), $_SERVER["PHP_SELF"], "",$param,"",'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Warehouse"), $_SERVER["PHP_SELF"], "e.label",$param,"",'',$sortfield,$sortorder); //print_liste_field_titre($langs->trans("DesiredStock"), $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Batch"), $_SERVER["PHP_SELF"], "pb.batch",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("l_eatby"), $_SERVER["PHP_SELF"], "pb.eatby",$param,"",'align="center"',$sortfield,$sortorder); @@ -289,7 +275,7 @@ if ($resql) print ' '; print ''; } - print ''; + print ''; print ''; print ''; print ''; @@ -356,7 +342,9 @@ if ($resql) print ''; diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index afcaec0bc6b..580ac0d94cd 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -546,7 +546,7 @@ class Entrepot extends CommonObject $result=''; $label = '' . $langs->trans("ShowWarehouse").''; - $label.= '
' . $langs->trans('Ref') . ': ' . $this->libelle; + $label.= '
' . $langs->trans('Ref') . ': ' . (empty($this->label)?$this->libelle:$this->label); if (! empty($this->lieu)) $label.= '
' . $langs->trans('LocationSummary').': '.$this->lieu; @@ -554,7 +554,7 @@ class Entrepot extends CommonObject $linkend=''; if ($withpicto) $result.=($link.img_object($label, 'stock', 'class="classfortooltip"').$linkend.' '); - $result.=$link.$this->libelle.$linkend; + $result.=$link.(empty($this->label)?$this->libelle:$this->label).$linkend; return $result; } diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 4af5b8a4d59..b750db87234 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -17,7 +17,7 @@ */ /** - * \file stock/productlot_card.php + * \file product/stock/productlot_card.php * \ingroup stock * \brief This file is an example of a php page * Initialy built by build_class_from_table on 2016-05-17 12:22 @@ -362,12 +362,6 @@ print ''."\n"; - - // Example 2 : Adding links to objects - //$somethingshown=$form->showLinkedObjectBlock($object); - //$linktoelem = $form->showLinkToObjectBlock($object); - //if ($linktoelem) print '
'.$linktoelem; - } diff --git a/htdocs/product/stock/productlot_list.php b/htdocs/product/stock/productlot_list.php index 65bd340fa85..2d01c95520b 100644 --- a/htdocs/product/stock/productlot_list.php +++ b/htdocs/product/stock/productlot_list.php @@ -1,6 +1,5 @@ - * Copyright (C) ---Put here your own copyright and developer email--- +/* Copyright (C) 2007-2016 Laurent Destailleur * * 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 @@ -17,7 +16,7 @@ */ /** - * \file stock/productlot_list.php + * \file product/stock/productlot_list.php * \ingroup stock * \brief This file is an example of a php page * Initialy built by build_class_from_table on 2016-05-17 12:22 @@ -46,11 +45,14 @@ if (! $res) die("Include of main fails"); require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'); require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -dol_include_once('/stock/class/productlot.class.php'); +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +dol_include_once('/product/stock/class/productlot.class.php'); // Load traductions files requiredby by page -$langs->load("stock"); +$langs->load("stocks"); +$langs->load("productbatch"); $langs->load("other"); +$langs->load("users"); // Get parameters $id = GETPOST('id','int'); @@ -60,7 +62,7 @@ $myparam = GETPOST('myparam','alpha'); $search_entity=GETPOST('search_entity','int'); -$search_fk_product=GETPOST('search_fk_product','int'); +$search_product=GETPOST('search_product','alpha'); $search_batch=GETPOST('search_batch','alpha'); $search_fk_user_creat=GETPOST('search_fk_user_creat','int'); $search_fk_user_modif=GETPOST('search_fk_user_modif','int'); @@ -79,7 +81,7 @@ if ($page == -1) { $page = 0; } $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortfield) $sortfield="t.rowid"; // Set here default search field +if (! $sortfield) $sortfield="t.batch"; // Set here default search field if (! $sortorder) $sortorder="ASC"; // Protection if external user @@ -91,34 +93,31 @@ if ($user->societe_id > 0) } // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array -$hookmanager->initHooks(array('productlotlist')); +$hookmanager->initHooks(array('productbatchlist')); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels -$extralabels = $extrafields->fetch_name_optionals_label('stock'); +$extralabels = $extrafields->fetch_name_optionals_label('productbatch'); $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); -// Load object if id or ref is provided as parameter -$object=new Productlot($db); -if (($id > 0 || ! empty($ref)) && $action != 'add') -{ - $result=$object->fetch($id,$ref); - if ($result < 0) dol_print_error($db); -} +// List of fields to search into when doing a "search in all" +$fieldstosearchall = array( + 't.ref'=>'Ref', + 't.note_public'=>'NotePublic', +); // Definition of fields for list $arrayfields=array( - -'t.entity'=>array('label'=>$langs->trans("Fieldentity"), 'checked'=>1), -'t.fk_product'=>array('label'=>$langs->trans("Fieldfk_product"), 'checked'=>1), -'t.batch'=>array('label'=>$langs->trans("Fieldbatch"), 'checked'=>1), -'t.fk_user_creat'=>array('label'=>$langs->trans("Fieldfk_user_creat"), 'checked'=>1), -'t.fk_user_modif'=>array('label'=>$langs->trans("Fieldfk_user_modif"), 'checked'=>1), -'t.import_key'=>array('label'=>$langs->trans("Fieldimport_key"), 'checked'=>1), - - + //'t.entity'=>array('label'=>$langs->trans("Fieldentity"), 'checked'=>1), + 't.batch'=>array('label'=>$langs->trans("Batch"), 'checked'=>1), + 't.fk_product'=>array('label'=>$langs->trans("Product"), 'checked'=>1), + 't.eatby'=>array('label'=>$langs->trans("EatByDate"), 'checked'=>1), + 't.sellby'=>array('label'=>$langs->trans("SellByDate"), 'checked'=>1), + //'t.import_key'=>array('label'=>$langs->trans("ImportKey"), 'checked'=>1), //'t.entity'=>array('label'=>$langs->trans("Entity"), 'checked'=>1, 'enabled'=>(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode))), - 't.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + //'t.fk_user_creat'=>array('label'=>$langs->trans("UserCreationShort"), 'checked'=>0, 'position'=>500), + //'t.fk_user_modif'=>array('label'=>$langs->trans("UserModificationShort"), 'checked'=>0, 'position'=>500), + 't.datec'=>array('label'=>$langs->trans("DateCreationShort"), 'checked'=>0, 'position'=>500), 't.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), //'t.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); @@ -131,17 +130,22 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab } } +// Load object if id or ref is provided as parameter +$object=new Productlot($db); +if (($id > 0 || ! empty($ref)) && $action != 'add') +{ + $result=$object->fetch($id,$ref); + if ($result < 0) dol_print_error($db); +} -/******************************************************************* -* ACTIONS -* -* Put here all code to do according to value of "action" parameter -********************************************************************/ +/* + * Actions + */ if (GETPOST('cancel')) { $action='list'; $massaction=''; } -if (! GETPOST('confirmmassaction')) { $massaction=''; } +if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; } $parameters=array(); $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks @@ -149,72 +153,50 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; +// Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") ||GETPOST("button_removefilter")) // All test are required to be compatible with all browsers { - -$search_entity=''; -$search_fk_product=''; -$search_batch=''; -$search_fk_user_creat=''; -$search_fk_user_modif=''; -$search_import_key=''; - - + $search_entity=''; + $search_product=''; + $search_batch=''; + $search_fk_user_creat=''; + $search_fk_user_modif=''; + $search_import_key=''; $search_date_creation=''; $search_date_update=''; + $toselect=''; $search_array_options=array(); } if (empty($reshook)) { - // Mass actions. Controls on number of lines checked - $maxformassaction=1000; - if (! empty($massaction) && count($toselect) < 1) - { - $error++; - setEventMessages($langs->trans("NoLineChecked"), null, "warnings"); - } - if (! $error && count($toselect) > $maxformassaction) - { - setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors'); - $error++; - } - - // Action to delete - if ($action == 'confirm_delete') - { - $result=$object->delete($user); - if ($result > 0) - { - // Delete OK - setEventMessages("RecordDeleted", null, 'mesgs'); - header("Location: ".dol_buildpath('/stock/list.php',1)); - exit; - } - else - { - if (! empty($object->errors)) setEventMessages(null,$object->errors,'errors'); - else setEventMessages($object->error,null,'errors'); - } - } + $objectclass='ProductLot'; + $objectlabel='LotSerial'; + $permtoread = $user->rights->stock->read; + $permtodelete = $user->rights->stock->delete; + $uploaddir = $conf->stock->dir_output; + //include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } -/*************************************************** -* VIEW -* -* Put here all code to build page -****************************************************/ +/* + * VIEW + */ -llxHeader('','MyPageName',''); +$now=dol_now(); $form=new Form($db); +$productstatic=new Product($db); + +//$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes"; +$help_url=''; +$title = $langs->trans('LotSerialList'); +llxHeader('', $title, $help_url); // Put here content of your page -$title = $langs->trans('MyModuleListTitle'); // Example : Adding jquery code print '
' . $langs->trans("Total") . '' . $langs->trans("JanuaryMin") . '' . $langs->trans("FebruaryMin") . '' . $langs->trans("MarchMin") . '' . $langs->trans("AprilMin") . '' . $langs->trans("MayMin") . '' . $langs->trans("JuneMin") . '' . $langs->trans("JulyMin") . '' . $langs->trans("AugustMin") . '' . $langs->trans("SeptemberMin") . '' . $langs->trans("OctoberMin") . '' . $langs->trans("NovemberMin") . '' . $langs->trans("DecemberMin") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . $row[1] . '' . price($row[2]) . '' . price($row[3]) . '' . price($row[4]) . '' . price($row[5]) . '' . price($row[6]) . '' . price($row[7]) . '' . price($row[8]) . '' . price($row[9]) . '' . price($row[10]) . '' . price($row[11]) . '' . price($row[12]) . '' . price($row[$i]) . '' . price($row[13]) . '
   '; if ($objp->fk_entrepot > 0) { - $warehousetmp->fetch($objp->fk_entrepot); + $warehousetmp->id=$objp->fk_entrepot; + $warehousetmp->label=$objp->warehouse_label; + //$warehousetmp->fetch($objp->fk_entrepot); print $warehousetmp->getNomUrl(1); } print '
'.$langs->trans("Fieldimport_key").'