From 977c18513da7181b1737324b17d6084503ec77a5 Mon Sep 17 00:00:00 2001 From: arnaud Date: Tue, 14 Feb 2017 12:00:56 +0100 Subject: [PATCH] FIX pdf supplier payment work --- htdocs/admin/supplier_payment.php | 6 +-- htdocs/core/class/conf.class.php | 3 ++ htdocs/core/lib/files.lib.php | 10 +++++ .../supplier_payment/pdf/pdf_cow.modules.php | 12 +++--- htdocs/fourn/class/paiementfourn.class.php | 43 +++++++++++++++++++ htdocs/fourn/paiement/card.php | 36 ++++++++++++++-- .../install/mysql/migration/5.0.0-6.0.0.sql | 2 + .../mysql/tables/llx_paiementfourn.sql | 3 +- 8 files changed, 101 insertions(+), 14 deletions(-) diff --git a/htdocs/admin/supplier_payment.php b/htdocs/admin/supplier_payment.php index 5cd1877ddb4..933ee22a062 100644 --- a/htdocs/admin/supplier_payment.php +++ b/htdocs/admin/supplier_payment.php @@ -130,8 +130,8 @@ else if ($action == 'specimen') { $modele=GETPOST('module','alpha'); - $facture = new Facture($db); - $facture->initAsSpecimen(); + $paiementFourn = new PaiementFourn($db); + $paiementFourn->initAsSpecimen(); // Search template files $file=''; $classname=''; $filefound=0; @@ -153,7 +153,7 @@ else if ($action == 'specimen') $module = new $classname($db); - if ($module->write_file($facture,$langs) > 0) + if ($module->write_file($paiementFourn,$langs) > 0) { header("Location: ".DOL_URL_ROOT."/document.php?modulepart=supplier_payment&file=SPECIMEN.pdf"); return; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 064beaa8226..82146bfe4b4 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -345,6 +345,9 @@ class Conf $this->fournisseur->facture=new stdClass(); $this->fournisseur->facture->dir_output =$rootfordata."/fournisseur/facture"; $this->fournisseur->facture->dir_temp =$rootfordata."/fournisseur/facture/temp"; + $this->fournisseur->payment=new stdClass(); + $this->fournisseur->payment->dir_output =$rootfordata."/fournisseur/payment"; + $this->fournisseur->payment->dir_temp =$rootfordata."/fournisseur/payment/temp"; // To prepare split of module fournisseur into fournisseur + supplier_order + supplier_invoice if (! empty($this->fournisseur->enabled) && empty($this->global->MAIN_USE_NEW_SUPPLIERMOD)) // By default, if module supplier is on, we set new properties diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 1f7974775b5..d48b7d9d1f3 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1874,6 +1874,16 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu $original_file=$conf->fournisseur->facture->dir_output.'/'.$original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture_fourn WHERE facnumber='".$db->escape($refname)."' AND entity=".$conf->entity; } + // Wrapping pour les rapport de paiements + else if ($modulepart == 'supplier_payment') + { + if ($fuser->rights->fournisseur->facture->lire || preg_match('/^specimen/i',$original_file)) + { + $accessallowed=1; + } + $original_file=$conf->fournisseur->payment->dir_output.'/'.$original_file; + $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."paiementfournisseur WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; + } // Wrapping pour les rapport de paiements else if ($modulepart == 'facture_paiement') diff --git a/htdocs/core/modules/supplier_payment/pdf/pdf_cow.modules.php b/htdocs/core/modules/supplier_payment/pdf/pdf_cow.modules.php index a7b9da6ded8..9f87b9870e4 100644 --- a/htdocs/core/modules/supplier_payment/pdf/pdf_cow.modules.php +++ b/htdocs/core/modules/supplier_payment/pdf/pdf_cow.modules.php @@ -24,7 +24,7 @@ * \brief Class file to generate the supplier invoices with the canelle model */ -require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; @@ -157,13 +157,11 @@ class pdf_cow extends ModelePDFSuppliersPayments $outputlangs->load("bills"); $outputlangs->load("products"); - if ($conf->fournisseur->dir_output.'/facture') + if ($conf->fournisseur->payment->dir_output) { $object->fetch_thirdparty(); - - $deja_regle = $object->getSommePaiement(); - //$amount_credit_notes_included = $object->getSumCreditNotesUsed(); - //$amount_deposits_included = $object->getSumDepositsUsed(); + + $total = $object->montant; // Definition of $dir and $file if ($object->specimen) @@ -175,7 +173,7 @@ class pdf_cow extends ModelePDFSuppliersPayments { $objectref = dol_sanitizeFileName($object->ref); $objectrefsupplier = dol_sanitizeFileName($object->ref_supplier); - $dir = $conf->fournisseur->payment->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'supplier_payment').$objectref; + $dir = $conf->fournisseur->payment->dir_output.'/'.$objectref; $file = $dir . "/" . $objectref . ".pdf"; if (! empty($conf->global->SUPPLIER_REF_IN_NAME)) $file = $dir . "/" . $objectref . ($objectrefsupplier?"_".$objectrefsupplier:"").".pdf"; } diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index 738c0eb716f..5d8279b1c54 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -660,6 +660,49 @@ class PaiementFourn extends Paiement } } + /** + * Create a document onto disk according to template model. + * + * @param string $modele Force template to use ('' to not force) + * @param Translate $outputlangs Object lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @return int <0 if KO, 0 if nothing done, >0 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) + { + global $conf, $user, $langs; + + $langs->load("suppliers"); + + // Set the model on the model name to use + if (empty($modele)) + { + if (! empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)) + { + $modele = $conf->global->SUPPLIER_PAYMENT_ADDON_PDF; + } + else + { + $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation + } + } + + if (empty($modele)) + { + return 0; + } + else + { + $modelpath = "core/modules/supplier_payment/pdf/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref); + } + } + + + /** * get the right way of payment * diff --git a/htdocs/fourn/paiement/card.php b/htdocs/fourn/paiement/card.php index 16e5dd1892e..9cb44a92bb8 100644 --- a/htdocs/fourn/paiement/card.php +++ b/htdocs/fourn/paiement/card.php @@ -43,6 +43,11 @@ $confirm = GETPOST('confirm','alpha'); $object = new PaiementFourn($db); +// PDF +$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); +$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); +$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); + /* * Actions */ @@ -134,6 +139,32 @@ if ($action == 'setdatep' && ! empty($_POST['datepday'])) } } +// Build document +if ($action == 'builddoc') +{ + // Save modele used + $object->fetch($id); + $object->fetch_thirdparty(); + + // Save last template used to generate document + if (GETPOST('model')) $object->setDocModel($user, GETPOST('model','alpha')); + + $outputlangs = $langs; + $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); + } + $result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action=''; + } +} + /* * View @@ -353,14 +384,13 @@ if ($result > 0) * Documents generes */ $ref=dol_sanitizeFileName($object->ref); - $subdir = get_exdir($object->id,2,0,0,$object,'supplier_payment').$ref; - $filedir = $conf->fournisseur->paiement->dir_output.'/'.get_exdir($object->id,2,0,0,$object,'supplier_payment').$ref; + $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$object->id; $genallowed=$user->rights->fournisseur->facture->creer; $delallowed=$user->rights->fournisseur->facture->supprimer; $modelpdf=(! empty($object->modelpdf)?$object->modelpdf:(empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)?'':$conf->global->SUPPLIER_PAYMENT_ADDON_PDF)); - print $formfile->showdocuments('supplier_payment',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,40,0,'','','',$societe->default_lang); + print $formfile->showdocuments('supplier_payment',$ref,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,40,0,'','','',$societe->default_lang); $somethingshown=$formfile->numoffiles; print '
'; diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index aa755daa09a..e7803281e67 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -98,3 +98,5 @@ CREATE TABLE llx_product_attribute_combination entity INT DEFAULT 1 NOT NULL ); +ALTER TABLE llx_paiementfourn ADD COLUMN model_pdf varchar(255); + diff --git a/htdocs/install/mysql/tables/llx_paiementfourn.sql b/htdocs/install/mysql/tables/llx_paiementfourn.sql index aba54627a09..0e9b1885c97 100644 --- a/htdocs/install/mysql/tables/llx_paiementfourn.sql +++ b/htdocs/install/mysql/tables/llx_paiementfourn.sql @@ -32,5 +32,6 @@ create table llx_paiementfourn num_paiement varchar(50), -- numero de paiement (cheque) note text, fk_bank integer NOT NULL, - statut smallint NOT NULL DEFAULT 0 + statut smallint NOT NULL DEFAULT 0, + model_pdf varchar(255) )ENGINE=innodb;