diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index 4b92ce7eebc..e995b06aa6b 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2013 Antoine Iauch * Copyright (C) 2013 Laurent Destailleur * Copyright (C) 2015 Raphaël Doursenaud * @@ -18,8 +18,8 @@ */ /** - * \file htdocs/compta/stats/cabyprodserv.php - * \brief Page reporting TO by Products & Services + * \file htdocs/compta/stats/cabyprodserv.php + * \brief Page reporting TO by Products & Services */ require '../../main.inc.php'; @@ -47,13 +47,13 @@ if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta"); $sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; if (! $sortorder) $sortorder="asc"; -if (! $sortfield) $sortfield="name"; +if (! $sortfield) $sortfield="ref"; // Category $selected_cat = (int) GETPOST('search_categ', 'int'); $subcat = false; if (GETPOST('subcat', 'alpha') === 'yes') { - $subcat = true; + $subcat = true; } // Date range @@ -132,7 +132,7 @@ $headerparams = array_merge($commonparams, $headerparams); $tableparams = array_merge($commonparams, $tableparams); foreach($allparams as $key => $value) { - $paramslink .= '&' . $key . '=' . $value; + $paramslink .= '&' . $key . '=' . $value; } @@ -148,28 +148,28 @@ $nom=$langs->trans("SalesTurnover").', '.$langs->trans("ByProductsAndServices"); if ($modecompta=="CREANCES-DETTES") { $calcmode=$langs->trans("CalcModeDebt"); - $calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; + $calcmode.='
('.$langs->trans("SeeReportInInputOutputMode",'','').')'; - $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); + $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); - $description=$langs->trans("RulesCADue"); + $description=$langs->trans("RulesCADue"); if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $description.= $langs->trans("DepositsAreNotIncluded"); + $description.= $langs->trans("DepositsAreNotIncluded"); } else { - $description.= $langs->trans("DepositsAreIncluded"); + $description.= $langs->trans("DepositsAreIncluded"); } - $builddate=time(); + $builddate=time(); } else { $calcmode=$langs->trans("CalcModeEngagement"); $calcmode.='
('.$langs->trans("SeeReportInDueDebtMode",'','').')'; - $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); + $period=$form->select_date($date_start,'date_start',0,0,0,'',1,0,1).' - '.$form->select_date($date_end,'date_end',0,0,0,'',1,0,1); - $description=$langs->trans("RulesCAIn"); - $description.= $langs->trans("DepositsAreIncluded"); + $description=$langs->trans("RulesCAIn"); + $description.= $langs->trans("DepositsAreIncluded"); - $builddate=time(); + $builddate=time(); } report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$tableparams,$calcmode); @@ -180,221 +180,226 @@ $catotal=0; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label,"; - $sql.= " sum(l.total_ht) as amount, sum(l.total_ttc) as amount_ttc"; - $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as l, ".MAIN_DB_PREFIX."product as p"; + $sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label,"; + $sql.= " SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,"; + $sql.= " SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty"; + $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as l, ".MAIN_DB_PREFIX."product as p"; if ($selected_cat === -2) // Without any category { - $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; + $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_product as cp ON p.rowid = cp.fk_product"; } else if ($selected_cat) // Into a specific category { - $sql.= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_product as cp"; + $sql.= ", ".MAIN_DB_PREFIX."categorie as c, ".MAIN_DB_PREFIX."categorie_product as cp"; } - $sql.= " WHERE l.fk_product = p.rowid"; + $sql.= " WHERE l.fk_product = p.rowid"; $sql.= " AND l.fk_facture = f.rowid"; - $sql.= " AND f.fk_statut in (1,2)"; - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $sql.= " AND f.type IN (0,1,2,5)"; - } else { + $sql.= " AND f.fk_statut in (1,2)"; + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $sql.= " AND f.type IN (0,1,2,5)"; + } else { $sql.= " AND f.type IN (0,1,2,3,5)"; - } - if ($date_start && $date_end) { - $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; - } + } + if ($date_start && $date_end) { + $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; + } if ($selected_cat === -2) // Without any category { - $sql.=" AND cp.fk_product is null"; + $sql.=" AND cp.fk_product is null"; } else if ($selected_cat) { // Into a specific category - $sql.= " AND (c.rowid = ".$selected_cat; - if ($subcat) $sql.=" OR c.fk_parent = " . $selected_cat; - $sql.= ")"; + $sql.= " AND (c.rowid = ".$selected_cat; + if ($subcat) $sql.=" OR c.fk_parent = " . $selected_cat; + $sql.= ")"; $sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid"; } - $sql.= " AND f.entity = ".$conf->entity; - $sql.= " GROUP BY p.rowid, p.ref, p.label"; - $sql.= " ORDER BY p.ref"; + $sql.= " AND f.entity = ".$conf->entity; + $sql.= " GROUP BY p.rowid, p.ref, p.label"; + $sql.= $db->order($sortfield,$sortorder); - dol_syslog("cabyprodserv", LOG_DEBUG); - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - $i=0; - while ($i < $num) { - $obj = $db->fetch_object($result); - $amount_ht[$obj->rowid] = $obj->amount; - $amount[$obj->rowid] = $obj->amount_ttc; - $name[$obj->rowid] = $obj->ref . ' - ' . $obj->label; - $catotal_ht+=$obj->amount; - $catotal+=$obj->amount_ttc; - $i++; + dol_syslog("cabyprodserv", LOG_DEBUG); + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + $i=0; + while ($i < $num) { + $obj = $db->fetch_object($result); + $amount_ht[$obj->rowid] = $obj->amount; + $amount[$obj->rowid] = $obj->amount_ttc; + $qty[$obj->rowid] = $obj->qty; + $name[$obj->rowid] = $obj->ref . ' - ' . $obj->label; + $catotal_ht+=$obj->amount; + $catotal+=$obj->amount_ttc; + $qtytotal+=$obj->qty; + $i++; + } + } else { + dol_print_error($db); } - } else { - dol_print_error($db); - } - // Show Array - $i=0; - print '
'; - // Extra parameters management - foreach($headerparams as $key => $value) - { - print ''; - } + // Show Array + $i=0; + print ''; + // Extra parameters management + foreach($headerparams as $key => $value) + { + print ''; + } - print ''; - // Category filter - print ''; - print ''; - print ''; - // Array header - print ""; - print_liste_field_titre( - $langs->trans("Product"), - $_SERVER["PHP_SELF"], - "name", - "", - $paramslink, - "", - $sortfield, - $sortorder - ); - print_liste_field_titre( - $langs->trans('AmountHT'), - $_SERVER["PHP_SELF"], - "amount_ht", - "", - $paramslink, - 'align="right"', - $sortfield, - $sortorder - ); - print_liste_field_titre( - $langs->trans("AmountTTC"), - $_SERVER["PHP_SELF"], - "amount_ttc", - "", - $paramslink, - 'align="right"', - $sortfield, - $sortorder - ); - print_liste_field_titre( - $langs->trans("Percentage"), - $_SERVER["PHP_SELF"], - "amount_ttc", - "", - $paramslink, - 'align="right"', - $sortfield, - $sortorder - ); - // TODO: statistics? - print "\n"; + print '
'; - print $langs->trans("Category") . ': ' . $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', true); - print ' '; - print $langs->trans("SubCats") . '? '; - print ''; - print ''; - print '
'; + // Category filter + print ''; + print ''; + print ''; + + // Array header + print ""; + print_liste_field_titre( + $langs->trans("Product"), + $_SERVER["PHP_SELF"], + "ref", + "", + $paramslink, + "", + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans('Quantity'), + $_SERVER["PHP_SELF"], + "qty", + "", + $paramslink, + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans("Percentage"), + $_SERVER["PHP_SELF"], + "qty", + "", + $paramslink, + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans('AmountHT'), + $_SERVER["PHP_SELF"], + "amount", + "", + $paramslink, + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans("AmountTTC"), + $_SERVER["PHP_SELF"], + "amount_ttc", + "", + $paramslink, + 'align="right"', + $sortfield, + $sortorder + ); + print_liste_field_titre( + $langs->trans("Percentage"), + $_SERVER["PHP_SELF"], + "amount_ttc", + "", + $paramslink, + 'align="right"', + $sortfield, + $sortorder + ); + print "\n"; - // Array Data - $var=true; + // Array Data + $var=true; - if (count($amount)) { - $arrayforsort=$name; - // defining arrayforsort - if ($sortfield == 'nom' && $sortorder == 'asc') { - asort($name); - $arrayforsort=$name; - } - if ($sortfield == 'nom' && $sortorder == 'desc') { - arsort($name); - $arrayforsort=$name; - } - if ($sortfield == 'amount_ht' && $sortorder == 'asc') { - asort($amount_ht); - $arrayforsort=$amount_ht; - } - if ($sortfield == 'amount_ht' && $sortorder == 'desc') { - arsort($amount_ht); - $arrayforsort=$amount_ht; - } - if ($sortfield == 'amount_ttc' && $sortorder == 'asc') { - asort($amount); - $arrayforsort=$amount; - } - if ($sortfield == 'amount_ttc' && $sortorder == 'desc') { - arsort($amount); - $arrayforsort=$amount; - } - foreach($arrayforsort as $key=>$value) { - $var=!$var; - print ""; + if (count($name)) { + foreach($name as $key=>$value) { + $var=!$var; + print ""; - // Product - $fullname=$name[$key]; - if ($key >= 0) { - $linkname=''.img_object($langs->trans("ShowProduct"),'product').' '.$fullname.''; - } else { - $linkname=$langs->trans("PaymentsNotLinkedToProduct"); - } + // Product + $fullname=$name[$key]; + if ($key >= 0) { + $linkname=''.img_object($langs->trans("ShowProduct"),'product').' '.$fullname.''; + } else { + $linkname=$langs->trans("PaymentsNotLinkedToProduct"); + } - print "\n"; + print "\n"; + + // Quantity + print ''; + + // Percent; + print ''; + + // Amount w/o VAT + print ''; + + // Amount with VAT + print ''; + + // Percent; + print ''; + + // TODO: statistics? + + print "\n"; + $i++; + } - // Amount w/o VAT - print ''; + // Total + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; - // Amount with VAT - print ''; - - // Percent; - print ''; - - // TODO: statistics? - - print "\n"; - $i++; - } - - // Total - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - $db->free($result); - } - print "
'; + print $langs->trans("Category") . ': ' . $formother->select_categories(Categorie::TYPE_PRODUCT, $selected_cat, 'search_categ', true); + print ' '; + print $langs->trans("SubCats") . '? '; + print ''; + print ''; + print '
".$linkname."".$linkname."'; + print $qty[$key]; + print ''.($qtytotal > 0 ? round(100 * $qty[$key] / $qtytotal, 2).'%' : ' ').''; + /*if ($key > 0) { + print ''; + } else { + print ''; + }*/ + print price($amount_ht[$key]); + //print ''; + print ''; + /*if ($key > 0) { + print ''; + } else { + print ''; + }*/ + print price($amount[$key]); + //print ''; + print ''.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : ' ').'
'; - /*if ($key > 0) { - print ''; - } else { - print ''; - }*/ - print price($amount_ht[$key]); - //print ''; - print '
'.$langs->trans("Total").''.price($catotal_ht).''.price($catotal).' 
'; - /*if ($key > 0) { - print ''; - } else { - print ''; - }*/ - print price($amount[$key]); - //print ''; - print ''.($catotal > 0 ? round(100 * $amount[$key] / $catotal, 2).'%' : ' ').'
'.$langs->trans("Total").''.price($catotal_ht).''.price($catotal).' 
"; - print '
'; + $db->free($result); + } + print ""; + print ''; } else { - // $modecompta != 'CREANCES-DETTES' - // "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an - // invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ? - // Because there is no way to know this, this report is not relevant. + // $modecompta != 'CREANCES-DETTES' + // "Calculation of part of each product for accountancy in this mode is not possible. When a partial payment (for example 5 euros) is done on an + // invoice with 2 product (product A for 10 euros and product B for 20 euros), what is part of paiment for product A and part of paiment for product B ? + // Because there is no way to know this, this report is not relevant. print '
'.$langs->trans("TurnoverPerProductInCommitmentAccountingNotRelevant") . '
'; } diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index dbdc56be3b2..691cfe7d72d 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -166,7 +166,7 @@ class modProduct extends DolibarrModules if (! empty($conf->barcode->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('p.barcode'=>'product')); if (! empty($conf->fournisseur->enabled)) $this->export_entities_array[$r]=array_merge($this->export_entities_array[$r],array('s.nom'=>'product','pf.ref_fourn'=>'product','pf.unitprice'=>'product')); // Add extra fields - $sql="SELECT name, label, type FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product'"; + $sql="SELECT name, label, type FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity IN (0, ".$conf->entity.')'; $resql=$this->db->query($sql); if ($resql) // This can fail when class is used on old database (during migration for example) { @@ -251,7 +251,8 @@ class modProduct extends DolibarrModules $this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.url'=>"PublicUrl",'p.accountancy_code_sell'=>"ProductAccountancySellCode",'p.accountancy_code_buy'=>"ProductAccountancyBuyCode",'p.note'=>"Note",'p.length'=>"Length",'p.surface'=>"Surface",'p.volume'=>"Volume",'p.weight'=>"Weight",'p.duration'=>"Duration",'p.customcode'=>'CustomCode','p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.tosell'=>"OnSell*",'p.tobuy'=>"OnBuy*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.datec'=>'DateCreation*'); if (! empty($conf->barcode->enabled)) $this->import_fields_array[$r]=array_merge($this->import_fields_array[$r],array('p.barcode'=>'BarCode')); // Add extra fields - $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' AND entity = ".$conf->entity; + $import_extrafield_sample=array(); + $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'product' entity IN (0, ".$conf->entity.')'; $resql=$this->db->query($sql); if ($resql) // This can fail when class is used on old database (during migration for example) { @@ -260,13 +261,14 @@ class modProduct extends DolibarrModules $fieldname='extra.'.$obj->name; $fieldlabel=ucfirst($obj->label); $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); + $import_extrafield_sample[$fieldname]=$fieldlabel; } } // End add extra fields $this->import_fieldshidden_array[$r]=array('extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'product'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.tosell'=>'^[0|1]$','p.tobuy'=>'^[0|1]$','p.fk_product_type'=>'^[0|1]$','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); - $this->import_examplevalues_array[$r]=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31'); - + $import_sample=array('p.ref'=>"PREF123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.tosell'=>"0 or 1",'p.tobuy'=>"0 or 1",'p.fk_product_type'=>"0 for product/1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31'); + $this->import_examplevalues_array[$r]=array_merge($import_sample,$import_extrafield_sample); if (! empty($conf->fournisseur->enabled)) { diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index f94b7205710..fd701cc333b 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -668,123 +668,6 @@ if ($action == "confirm_cancel" && GETPOST('confirm')=="yes" && GETPOST('detail_ } } -if ($action == "confirm_paid" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->to_paid) -{ - $object = new ExpenseReport($db); - $object->fetch($id); - - $result = $object->setPaid($user); - - if ($result > 0) - { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (! empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model=$object->modelpdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - } - } - - if ($result > 0) - { - if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) - { - // Send mail - - // TO - $destinataire = new User($db); - $destinataire->fetch($object->fk_user_author); - $emailTo = $destinataire->email; - - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_paid); - $emailFrom = $expediteur->email; - - // SUBJECT - $subject = "' ERP - Note de frais payée"; - - // CONTENT - $message = "Bonjour {$destinataire->firstname},\n\n"; - $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n"; - $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n"; - $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; - $message.= "Bien cordialement,\n' SI"; - - // Génération du pdf avant attachement - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message); - - if(!$mailfile->error): - - // SEND - $result=$mailfile->sendfile(); - if ($result): - // Insert écriture dans le compte courant - $idTrip = $id; - $idAccount = 1; - - $object = new ExpenseReport($db); - $object->fetch($idTrip); - - $datePaiement = explode("-",$object->date_paiement); - - $dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]); - $operation = $object->code_paiement; - $label = "Règlement ".$object->ref; - $amount = - price2num($object->total_ttc); - $num_chq = ''; - $cat1 = ''; - - $user = new User($db); - $user->fetch($object->fk_user_paid); - - $acct=new Account($db,$idAccount); - $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); - - if ($insertid > 0): - $sql = " UPDATE ".MAIN_DB_PREFIX."expensereport as d"; - $sql.= " SET integration_compta = 1, fk_bank_account = $idAccount"; - $sql.= " WHERE rowid = $idTrip"; - $resql=$db->query($sql); - if($result): - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - else: - dol_print_error($db); - endif; - else: - dol_print_error($db,$acct->error); - endif; - endif; - - else: - - $mesg="Impossible d'envoyer l'email."; - - endif; - // END - Send mail - } - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && $user->rights->expensereport->creer) { $object = new ExpenseReport($db); @@ -829,16 +712,96 @@ if ($action == "confirm_brouillonner" && GETPOST('confirm')=="yes" && $id > 0 && } } -if ($action == 'set_paid') +if ($action == 'set_paid' && $id > 0 && $user->rights->expensereport->to_paid) { - if ($object->set_paid($id) >= 0) + $object = new ExpenseReport($db); + $object->fetch($id); + + $result = $object->set_paid($id, $user); + + if ($result > 0) { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; + // Define output language + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + if ($result > 0) + { + if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) + { + // Send mail + + // TO + $destinataire = new User($db); + $destinataire->fetch($object->fk_user_author); + $emailTo = $destinataire->email; + + // FROM + $expediteur = new User($db); + $expediteur->fetch($user->id); + $emailFrom = $expediteur->email; + + // SUBJECT + $subject = "'ERP - Note de frais payée"; + + // CONTENT + $message = "Bonjour {$destinataire->firstname},\n\n"; + $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n"; + $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n"; + $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; + $message.= "Bien cordialement,\n' SI"; + + // Generate pdf before attachment + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message); + + if(!$mailfile->error): + + // SEND + $result=$mailfile->sendfile(); + if ($result): + + // Retour + if($result): + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + else: + dol_print_error($db); + endif; + + else: + dol_print_error($db,$acct->error); + endif; + + else: + + $mesg="Impossible d'envoyer l'email."; + + endif; + // END - Send mail + } + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); } - else { - setEventMessage($object->error, 'errors'); - } } if ($action == "addline") @@ -1311,7 +1274,7 @@ else print ''.$langs->trans("AUTHORPAIEMENT").''; print ''; $userfee=new User($db); - $userfee->fetch($object->fk_user_paid); + $userfee->fetch($user->id); print $userfee->getNomUrl(1); print ''; @@ -2005,9 +1968,9 @@ if ($action != 'create' && $action != 'edit') print ''; } - if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer) + if (round($remaintopay) == 0 && $object->paid == 0) { - print '"; + print '"; } // Cancel diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 093bf2db705..0aa45386a85 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2015 Laurent Destailleur + * Copyright (C) 2015 Alexandre Spangaro * * 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 @@ -88,8 +89,6 @@ class ExpenseReport extends CommonObject var $fk_user_approve; // Paiement - var $date_paiement; - var $fk_user_paid; var $user_paid_infos; /* @@ -241,7 +240,6 @@ class ExpenseReport extends CommonObject $sql.= " , fk_user_author = ".($user->id > 0 ? "'".$user->id."'":"null"); $sql.= " , fk_user_validator = ".($this->fk_user_validator > 0 ? $this->fk_user_validator:"null"); $sql.= " , fk_user_valid = ".($this->fk_user_valid > 0 ? $this->fk_user_valid:"null"); - $sql.= " , fk_user_paid = ".($this->fk_user_paid > 0 ? $this->fk_user_paid:"null"); $sql.= " , fk_statut = ".($this->fk_statut >= 0 ? $this->fk_statut:'0'); $sql.= " , fk_c_paiement = ".($this->fk_c_paiement > 0 ? $this->fk_c_paiement:"null"); $sql.= " , note_public = ".(!empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"''"); @@ -277,9 +275,9 @@ class ExpenseReport extends CommonObject $sql.= " d.detail_refuse, d.detail_cancel, d.fk_user_refuse, d.fk_user_cancel,"; // ACTIONS $sql.= " d.date_refuse, d.date_cancel,"; // ACTIONS $sql.= " d.total_ht, d.total_ttc, d.total_tva,"; // TOTAUX (int) - $sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valid, d.date_approve, d.date_paiement,"; // DATES (datetime) + $sql.= " d.date_debut, d.date_fin, d.date_create, d.date_valid, d.date_approve,"; // DATES (datetime) $sql.= " d.fk_user_author, d.fk_user_validator, d.fk_statut as status, d.fk_c_paiement,"; - $sql.= " d.fk_user_valid, d.fk_user_approve, d.fk_user_paid,"; + $sql.= " d.fk_user_valid, d.fk_user_approve,"; $sql.= " dp.libelle as libelle_paiement, dp.code as code_paiement"; // INNER JOIN paiement $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as d LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as dp ON d.fk_c_paiement = dp.id"; if ($ref) $sql.= " WHERE d.ref = '".$this->db->escape($ref)."'"; @@ -305,7 +303,6 @@ class ExpenseReport extends CommonObject $this->date_debut = $this->db->jdate($obj->date_debut); $this->date_fin = $this->db->jdate($obj->date_fin); - $this->date_paiement = $this->db->jdate($obj->date_paiement); $this->date_valid = $this->db->jdate($obj->date_valid); $this->date_approve = $this->db->jdate($obj->date_approve); $this->date_create = $this->db->jdate($obj->date_create); @@ -318,7 +315,6 @@ class ExpenseReport extends CommonObject $this->fk_user_refuse = $obj->fk_user_refuse; $this->fk_user_cancel = $obj->fk_user_cancel; $this->fk_user_approve = $obj->fk_user_approve; - $this->fk_user_paid = $obj->fk_user_paid; $user_author = new User($this->db); if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author); @@ -341,13 +337,6 @@ class ExpenseReport extends CommonObject $this->user_valid_infos = dolGetFirstLastname($user_valid->firstname, $user_valid->lastname); } - if ($this->fk_statut==6) - { - $user_paid = new User($this->db); - if ($this->fk_user_paid > 0) $user_paid->fetch($this->fk_user_paid); - $this->user_paid_infos = dolGetFirstLastname($user_paid->firstname, $user_paid->lastname); - } - $this->libelle_statut = $obj->libelle_statut; $this->libelle_paiement = $obj->libelle_paiement; $this->code_statut = $obj->code_statut; @@ -376,13 +365,16 @@ class ExpenseReport extends CommonObject * Classify the expense report as paid * * @param int $id id of expense report - * @return int <0 if KO, >0 if OK + * @param user $fuser User + * @return int <0 if KO, >0 if OK */ - function set_paid($id) + function set_paid($id, $fuser) { - $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport SET fk_statut = 6"; + $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport"; + $sql.= " SET fk_statut = 6; $sql.= " WHERE rowid = $id AND fk_statut = 5"; + dol_syslog(get_class($this)."::set_paid sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -1017,41 +1009,6 @@ class ExpenseReport extends CommonObject } } - /** - * setPaid - * - * @param User $fuser User - * @return int <0 if KO, >0 if OK - */ - function setPaid($fuser) - { - $now= dol_now(); - - $this->date_paiement = $this->db->idate($now); - if ($this->fk_statut != 6) - { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_statut = 6, fk_user_paid = ".$fuser->id.","; - $sql.= " date_paiement='".$this->db->idate($this->date_paiement)."'"; - $sql.= ' WHERE rowid = '.$this->id; - - dol_syslog(get_class($this)."::setPaid sql=".$sql, LOG_DEBUG); - if ($this->db->query($sql)) - { - return 1; - } - else - { - $this->error=$this->db->error(); - return -1; - } - } - else - { - dol_syslog(get_class($this)."::set_paid expensereport already with paid status", LOG_WARNING); - } - } - /** * set_unpaid * diff --git a/htdocs/expensereport/export_csv.php b/htdocs/expensereport/export_csv.php index 3a2010ce340..817d651c3e8 100644 --- a/htdocs/expensereport/export_csv.php +++ b/htdocs/expensereport/export_csv.php @@ -126,9 +126,8 @@ if (isset($_POST['action'])) $outputlangs = $langs; $outputlangs->charset_output = 'UTF-8'; - $sql = "SELECT d.rowid, d.ref, d.date_paiement, d.total_ht, d.total_tva, d.total_ttc"; + $sql = "SELECT d.rowid, d.ref, d.total_ht, d.total_tva, d.total_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as d"; - $sql.= " WHERE date_paiement LIKE '".$select_date."%'"; $sql.= " ORDER BY d.rowid"; $result = $db->query($sql); @@ -146,7 +145,7 @@ if (isset($_POST['action'])) $objet->total_tva = number_format($objet->total_tva,2); $objet->total_ttc = number_format($objet->total_ttc,2); $objet->ref = trim($objet->ref); - $ligne.= "{$objet->rowid}, {$objet->ref}, ----, {$objet->date_paiement}, {$objet->total_ht}, {$objet->total_tva}, {$objet->total_ttc}\n"; + $ligne.= "{$objet->rowid}, {$objet->ref}, ----, {$objet->total_ht}, {$objet->total_tva}, {$objet->total_ttc}\n"; $ligne.= "--->, Ligne, Type, Description, ----, ----, ----\n"; diff --git a/htdocs/expensereport/synchro_compta.php b/htdocs/expensereport/synchro_compta.php index 58fcbaee301..90eb4bd4674 100644 --- a/htdocs/expensereport/synchro_compta.php +++ b/htdocs/expensereport/synchro_compta.php @@ -33,8 +33,6 @@ if ($_GET["action"] == 'confirm_ndf_to_account' && $_GET["confirm"] == "yes"): $expensereport = new ExpenseReport($db); $expensereport->fetch($idTrip,$user); - $datePaiement = explode("-",$expensereport->date_paiement); - $dateop = dol_mktime(12,0,0,$datePaiement[1],$datePaiement[2],$datePaiement[0]); $operation = $expensereport->code_paiement; $label = "Règlement ".$expensereport->ref; @@ -43,7 +41,7 @@ if ($_GET["action"] == 'confirm_ndf_to_account' && $_GET["confirm"] == "yes"): $cat1 = ''; $user = new User($db); - $user->fetch($expensereport->fk_user_paid); + $user->fetch($user->id); $acct=new Account($db,$idAccount); $insertid = $acct->addline($dateop, $operation, $label, $amount, $num_chq, $cat1, $user); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 5f207693f57..aa43d763e84 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -231,7 +231,6 @@ CREATE TABLE llx_expensereport ( date_approve datetime, date_refuse datetime, date_cancel datetime, - date_paiement datetime, tms timestamp, fk_user_author integer NOT NULL, fk_user_modif integer DEFAULT NULL, @@ -240,7 +239,6 @@ CREATE TABLE llx_expensereport ( fk_user_approve integer DEFAULT NULL, fk_user_refuse integer DEFAULT NULL, fk_user_cancel integer DEFAULT NULL, - fk_user_paid integer DEFAULT NULL, fk_statut integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé fk_c_paiement integer DEFAULT NULL, paid smallint default 0 NOT NULL, diff --git a/htdocs/install/mysql/tables/llx_expensereport.sql b/htdocs/install/mysql/tables/llx_expensereport.sql index 879623b6b7e..2e7e3911f99 100755 --- a/htdocs/install/mysql/tables/llx_expensereport.sql +++ b/htdocs/install/mysql/tables/llx_expensereport.sql @@ -34,7 +34,6 @@ CREATE TABLE llx_expensereport ( date_approve datetime, date_refuse datetime, date_cancel datetime, - date_paiement datetime, tms timestamp, fk_user_author integer NOT NULL, fk_user_modif integer DEFAULT NULL, @@ -43,7 +42,6 @@ CREATE TABLE llx_expensereport ( fk_user_approve integer DEFAULT NULL, fk_user_refuse integer DEFAULT NULL, fk_user_cancel integer DEFAULT NULL, - fk_user_paid integer DEFAULT NULL, fk_statut integer NOT NULL, -- 1=brouillon, 2=validé (attente approb), 4=annulé, 5=approuvé, 6=payed, 99=refusé fk_c_paiement integer DEFAULT NULL, paid smallint default 0 NOT NULL, diff --git a/htdocs/support/index.php b/htdocs/support/index.php index dbde74ed857..afd7a4f6338 100644 --- a/htdocs/support/index.php +++ b/htdocs/support/index.php @@ -194,7 +194,7 @@ print ''; print ''; print ''; -#$urlwiki='http://wiki.dolibarr.org/index.php/List of Dolibarr partners and providers'; +//$urlwiki='http://wiki.dolibarr.org/index.php/List of Dolibarr partners and providers'; $urlwiki='http://partners.dolibarr.org'; print ''; print ''; @@ -229,7 +229,7 @@ print '
'; print ''; print ''; -#$urlwiki='http://wiki.dolibarr.org/index.php/List of Dolibarr partners and providers'; +//$urlwiki='http://wiki.dolibarr.org/index.php/List of Dolibarr partners and providers'; $urlwiki='http://partners.dolibarr.org'; print ''; print '';