From 135342b085790702941c5b8eba86fc5ab97e1c89 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 25 Oct 2012 15:47:35 +0200 Subject: [PATCH 1/2] fix minor bugs in order creation from another object --- htdocs/commande/fiche.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 641fcbce1ae..9cfc131f979 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1382,8 +1382,8 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines(); $objectsrc->fetch_thirdparty(); - $projectid = (!empty($objectsrc->fk_project)?$object->fk_project:''); - $ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); + $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); + $ref_client = (!empty($objectsrc->ref_client)?$objectsrc->ref_client:''); $soc = $objectsrc->client; $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); From 2272d13f5af0793d8e1d5b00127bf40c17fcc149 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 25 Oct 2012 15:50:43 +0200 Subject: [PATCH 2/2] fix minor bug in invoice creation from another object --- htdocs/fourn/facture/fiche.php | 4102 ++++++++++++++++---------------- 1 file changed, 2051 insertions(+), 2051 deletions(-) diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 9f9a90333b3..4d58652bf27 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -1,2056 +1,2056 @@ - - * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2004 Christophe Combelles - * Copyright (C) 2005 Marc Barilley - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2010-2012 Juanjo Menent - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/fourn/facture/fiche.php - * \ingroup facture, fournisseur - * \brief Page for supplier invoice card (view, edit, validate) - */ - -require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; - - -$langs->load('bills'); -$langs->load('suppliers'); -$langs->load('companies'); - -$mesg=''; -$errors=array(); -$id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int')); -$action = GETPOST("action"); -$confirm = GETPOST("confirm"); - -//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)); - -// Security check -$socid=''; -if (! empty($user->societe_id)) $socid=$user->societe_id; -$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); - -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; -$hookmanager=new HookManager($db); -$hookmanager->initHooks(array('invoicesuppliercard')); - -$object=new FactureFournisseur($db); - - - -/* - * Actions -*/ - -// Action clone object -if ($action == 'confirm_clone' && $confirm == 'yes') -{ - if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) - { - $mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
'; - } - else - { - $result=$object->createFromClone($id); - if ($result > 0) - { - header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); - exit; - } - else - { - $langs->load("errors"); - $mesg='
'.$langs->trans($object->error).'
'; - $action=''; - } - } -} - -elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->facture->valider) -{ - $idwarehouse=GETPOST('idwarehouse'); - - $object->fetch($id); - $object->fetch_thirdparty(); - - // Check parameters - if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1)) - { - $langs->load("stocks"); - if (! $idwarehouse || $idwarehouse == -1) - { - $error++; - $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")); - $action=''; - } - } - - if (! $error) - { - $result = $object->validate($user,'',$idwarehouse); - if ($result < 0) - { - $mesg='
'.$object->error.'
'; - } - } -} - -elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) -{ - $object->fetch($id); - $object->fetch_thirdparty(); - $result=$object->delete($id); - if ($result > 0) - { - header('Location: index.php'); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } -} - -elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $ret = $object->deleteline(GETPOST('lineid')); - if ($ret > 0) - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } -} - -elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $result=$object->set_paid($user); -} - -// Set supplier ref -elseif ($action == 'setfacnumber' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $result=$object->set_ref_supplier($user, GETPOST('facnumber')); -} - -// Set label -elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $object->label=$_POST['label']; - $result=$object->update($user); - if ($result < 0) dol_print_error($db); -} - -elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $object->date=dol_mktime(12,0,0,$_POST['datefmonth'],$_POST['datefday'],$_POST['datefyear']); - if ($object->date_echeance < $object->date) $object->date_echeance=$object->date; - $result=$object->update($user); - if ($result < 0) dol_print_error($db,$object->error); -} -elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $object->date_echeance=dol_mktime(12,0,0,$_POST['date_lim_reglementmonth'],$_POST['date_lim_reglementday'],$_POST['date_lim_reglementyear']); + + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004 Christophe Combelles + * Copyright (C) 2005 Marc Barilley + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2010-2012 Juanjo Menent + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/fourn/facture/fiche.php + * \ingroup facture, fournisseur + * \brief Page for supplier invoice card (view, edit, validate) + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + + +$langs->load('bills'); +$langs->load('suppliers'); +$langs->load('companies'); + +$mesg=''; +$errors=array(); +$id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int')); +$action = GETPOST("action"); +$confirm = GETPOST("confirm"); + +//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)); + +// Security check +$socid=''; +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture'); + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; +$hookmanager=new HookManager($db); +$hookmanager->initHooks(array('invoicesuppliercard')); + +$object=new FactureFournisseur($db); + + + +/* + * Actions +*/ + +// Action clone object +if ($action == 'confirm_clone' && $confirm == 'yes') +{ + if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) + { + $mesg='
'.$langs->trans("NoCloneOptionsSpecified").'
'; + } + else + { + $result=$object->createFromClone($id); + if ($result > 0) + { + header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); + exit; + } + else + { + $langs->load("errors"); + $mesg='
'.$langs->trans($object->error).'
'; + $action=''; + } + } +} + +elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->facture->valider) +{ + $idwarehouse=GETPOST('idwarehouse'); + + $object->fetch($id); + $object->fetch_thirdparty(); + + // Check parameters + if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1)) + { + $langs->load("stocks"); + if (! $idwarehouse || $idwarehouse == -1) + { + $error++; + $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")); + $action=''; + } + } + + if (! $error) + { + $result = $object->validate($user,'',$idwarehouse); + if ($result < 0) + { + $mesg='
'.$object->error.'
'; + } + } +} + +elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) +{ + $object->fetch($id); + $object->fetch_thirdparty(); + $result=$object->delete($id); + if ($result > 0) + { + header('Location: index.php'); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } +} + +elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $ret = $object->deleteline(GETPOST('lineid')); + if ($ret > 0) + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } +} + +elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $result=$object->set_paid($user); +} + +// Set supplier ref +elseif ($action == 'setfacnumber' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $result=$object->set_ref_supplier($user, GETPOST('facnumber')); +} + +// Set label +elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $object->label=$_POST['label']; + $result=$object->update($user); + if ($result < 0) dol_print_error($db); +} + +elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $object->date=dol_mktime(12,0,0,$_POST['datefmonth'],$_POST['datefday'],$_POST['datefyear']); + if ($object->date_echeance < $object->date) $object->date_echeance=$object->date; + $result=$object->update($user); + if ($result < 0) dol_print_error($db,$object->error); +} +elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $object->date_echeance=dol_mktime(12,0,0,$_POST['date_lim_reglementmonth'],$_POST['date_lim_reglementday'],$_POST['date_lim_reglementyear']); if ($object->date_echeance < $object->date) { $object->date_echeance=$object->date; setEventMessage($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"),'warnings'); } - $result=$object->update($user); - if ($result < 0) dol_print_error($db,$object->error); -} -elseif ($action == 'setnote_public' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); - if ($result < 0) dol_print_error($db,$object->error); -} -elseif ($action == 'setnote' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); - if ($result < 0) dol_print_error($db,$object->error); -} - -// Delete payment -elseif ($action == 'deletepaiement') -{ - $object->fetch($id); - if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) - { - $paiementfourn = new PaiementFourn($db); - $paiementfourn->fetch(GETPOST('paiement_id')); - $result=$paiementfourn->delete(); - if ($result < 0) $mesg='
'.$paiementfourn->error.'
'; - } -} - -// Create -elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) -{ - $error=0; - - $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); - $datedue=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); - - if ($datefacture == '') - { - $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'
'; - $action='create'; - $_GET['socid']=$_POST['socid']; - $error++; - } - if (! GETPOST('facnumber')) - { - $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
'; - $action='create'; - $_GET['socid']=$_POST['socid']; - $error++; - } - - if (! $error) - { - $db->begin(); - - // Creation facture - $object->ref = $_POST['facnumber']; - $object->socid = $_POST['socid']; - $object->libelle = $_POST['libelle']; - $object->date = $datefacture; - $object->date_echeance = $datedue; - $object->note_public = $_POST['note']; - - // If creation from another object of another module - if ($_POST['origin'] && $_POST['originid']) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = $_POST['origin']; - /*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - }*/ - - // For compatibility - if ($element == 'order') { - $element = $subelement = 'commande'; - } - if ($element == 'propal') { - $element = 'comm/propal'; $subelement = 'propal'; - } - if ($element == 'contract') { - $element = $subelement = 'contrat'; - } - if ($element == 'order_supplier') { - $element = 'fourn'; $subelement = 'fournisseur.commande'; - } - - $object->origin = $_POST['origin']; - $object->origin_id = $_POST['originid']; - - $id = $object->create($user); - - // Add lines - if ($id > 0) - { - require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'; - $classname = ucfirst($subelement); - if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; - $srcobject = new $classname($db); - - $result=$srcobject->fetch($_POST['originid']); - if ($result > 0) - { - $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); - - $num=count($lines); - for ($i = 0; $i < $num; $i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - - // Dates - // TODO mutualiser - $date_start=$lines[$i]->date_debut_prevue; - if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; - if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; - $date_end=$lines[$i]->date_fin_prevue; - if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; - if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; - - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->qty, - $lines[$i]->fk_product, - $lines[$i]->remise_percent, - $date_start, - $date_end, - 0, - $lines[$i]->info_bits, - 'HT', - $product_type - ); - - if ($result < 0) - { - $error++; - break; - } - } - } - else - { - $error++; - } - } - else - { - $error++; - } - } - // If some invoice's lines already known - else - { - $id = $object->create($user); - if ($id < 0) - { - $error++; - } - - if (! $error) - { - for ($i = 1 ; $i < 9 ; $i++) - { - $label = $_POST['label'.$i]; - $amountht = price2num($_POST['amount'.$i]); - $amountttc = price2num($_POST['amountttc'.$i]); - $tauxtva = price2num($_POST['tauxtva'.$i]); - $qty = $_POST['qty'.$i]; - $fk_product = $_POST['fk_product'.$i]; - if ($label) - { - if ($amountht) - { - $price_base='HT'; $amount=$amountht; - } - else - { - $price_base='TTC'; $amount=$amountttc; - } - $atleastoneline=1; - - $product=new Product($db); - $product->fetch($_POST['idprod'.$i]); - - $ret=$object->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base); - if ($ret < 0) $error++; - } - } - } - } - - if ($error) - { - $langs->load("errors"); - $db->rollback(); - $mesg='
'.$langs->trans($object->error).'
'; - $action='create'; - $_GET['socid']=$_POST['socid']; - } - else - { - $db->commit(); - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); - exit; - } - } -} - -// Modification d'une ligne -elseif ($action == 'update_line') -{ - if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification - { - $object->fetch($id); - $object->fetch_thirdparty(); - - if ($_POST['puht']) - { - $pu=$_POST['puht']; - $price_base_type='HT'; - } - if ($_POST['puttc']) - { - $pu=$_POST['puttc']; - $price_base_type='TTC'; - } - - if (GETPOST('idprod')) - { - $prod = new Product($db); - $prod->fetch($_POST['idprod']); - $label = $prod->description; - if (trim($_POST['desc']) != trim($label)) $label=$_POST['desc']; - - $type = $prod->type; - } - else - { - - $label = $_POST['desc']; - $type = $_POST["type"]?$_POST["type"]:0; - - } - - $localtax1tx= get_localtax($_POST['tauxtva'], 1, $object->thirdparty); - $localtax2tx= get_localtax($_POST['tauxtva'], 2, $object->thirdparty); - $remise_percent=GETPOST('remise_percent'); - - $result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1tx, $localtax2tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent); - if ($result >= 0) - { - unset($_POST['label']); - } - } -} - -elseif ($action == 'addline') -{ - $ret=$object->fetch($id); - if ($ret < 0) - { - dol_print_error($db,$object->error); - exit; - } - $ret=$object->fetch_thirdparty(); - - if ($_POST['idprodfournprice']) // > 0 or -1 - { - $product=new Product($db); - $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']); // Just to see if a price exists for the quantity. Not used to found vat - - if ($idprod > 0) - { - $result=$product->fetch($idprod); - - // cas special pour lequel on a les meme reference que le fournisseur - // $label = '['.$product->ref.'] - '. $product->libelle; - $label = $product->description; - $label.= $product->description && $_POST['np_desc'] ? "\n" : ""; - $label.= $_POST['np_desc']; - - $tvatx=get_default_tva($object->thirdparty, $mysoc, $product->id, $_POST['idprodfournprice']); - - $localtax1tx= get_localtax($tvatx, 1, $object->thirdparty); - $localtax2tx= get_localtax($tvatx, 2, $object->thirdparty); - $remise_percent=GETPOST('remise_percent'); - $type = $product->type; - - $result=$object->addline($label, $product->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $_POST['qty'], $idprod, $remise_percent); - - } - if ($idprod == -1) - { - // Quantity too low - $langs->load("errors"); - $mesg='
'.$langs->trans("ErrorQtyTooLowForThisSupplier").'
'; - } - } - else - { - $tauxtva = price2num($_POST['tauxtva']); - $localtax1tx= get_localtax($tauxtva, 1, $object->thirdparty); - $localtax2tx= get_localtax($tauxtva, 2, $object->thirdparty); - $remise_percent=GETPOST('remise_percent'); - - if (! $_POST['dp_desc']) - { - $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")).'
'; - } - else - { - $type = $_POST["type"]; - if (! empty($_POST['amount'])) - { - $ht = price2num($_POST['amount']); - $price_base_type = 'HT'; - - //$desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0) - $result=$object->addline($_POST['dp_desc'], $ht, $tauxtva, $localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, 0, $price_base_type, $type); - } - else - { - $ttc = price2num($_POST['amountttc']); - $ht = $ttc / (1 + ($tauxtva / 100)); - $price_base_type = 'HT'; - $result=$object->addline($_POST['dp_desc'], $ht, $tauxtva,$localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, 0, $price_base_type, $type); - } - } - } - - //print "xx".$tva_tx; exit; - if ($result > 0) - { - // Define output language - $outputlangs = $langs; - $newlang=GETPOST('lang_id','alpha'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['idprodfournprice']); - unset($_POST['remise_percent']); - unset($_POST['dp_desc']); - unset($_POST['np_desc']); - unset($_POST['pu']); - unset($_POST['tva_tx']); - unset($_POST['label']); - unset($localtax1_tx); - unset($localtax2_tx); - } - else if (empty($mesg)) - { - $mesg='
'.$object->error.'
'; - } - - $action = ''; -} - -elseif ($action == 'classin') -{ - $object->fetch($id); - $result=$object->setProject($_POST['projectid']); -} - - -// Set invoice to draft status -elseif ($action == 'edit' && $user->rights->fournisseur->facture->creer) -{ - $object->fetch($id); - - $totalpaye = $object->getSommePaiement(); - $resteapayer = $object->total_ttc - $totalpaye; - - // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees - //$ventilExportCompta = $object->getVentilExportCompta(); - - // On verifie si aucun paiement n'a ete effectue - if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) - { - $object->set_draft($user); - - $outputlangs = $langs; - if (! empty($_REQUEST['lang_id'])) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - } -} - -// Set invoice to validated/unpaid status -elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer) -{ - $result = $object->fetch($id); - if ($object->statut == 2 - || ($object->statut == 3 && $object->close_code != 'replaced')) - { - $result = $object->set_unpaid($user); - if ($result > 0) - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit; - } - else - { - $mesg='
'.$object->error.'
'; - } - } -} - -// Add file in email form -if (GETPOST('addfile')) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - // Set tmp user directory TODO Use a dedicated directory for temp mails files - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; - - dol_add_file_process($upload_dir_tmp,0,0); - $action='presend'; -} - -// Remove file in email form -if (! empty($_POST['removedfile'])) -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - // Set tmp user directory - $vardir=$conf->user->dir_output."/".$user->id; - $upload_dir_tmp = $vardir.'/temp'; - - // TODO Delete only files that was uploaded from email form - dol_remove_file_process($_POST['removedfile'],0); - $action='presend'; -} - -// Send mail -if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) -{ - $langs->load('mails'); - - $object->fetch($id); - $result=$object->fetch_thirdparty(); - if ($result > 0) - { -// $ref = dol_sanitizeFileName($object->ref); -// $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; - -// if (is_readable($file)) -// { - if ($_POST['sendto']) - { - // Le destinataire a ete fourni via le champ libre - $sendto = $_POST['sendto']; - $sendtoid = 0; - } - elseif ($_POST['receiver'] != '-1') - { - // Recipient was provided from combo list - if ($_POST['receiver'] == 'thirdparty') // Id of third party - { - $sendto = $object->client->email; - $sendtoid = 0; - } - else // Id du contact - { - $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); - $sendtoid = $_POST['receiver']; - } - } - - if (dol_strlen($sendto)) - { - $langs->load("commercial"); - - $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; - $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; - $message = $_POST['message']; - $sendtocc = $_POST['sendtocc']; - $deliveryreceipt = $_POST['deliveryreceipt']; - - if ($action == 'send') - { - if (dol_strlen($_POST['subject'])) $subject=$_POST['subject']; - else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref; - $actiontypecode='AC_SUP_ORD'; - $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; - if ($message) - { - $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; - $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; - $actionmsg.=$message; - } - $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); - } - - // Create form object - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - - $attachedfiles=$formmail->get_attached_files(); - $filepath = $attachedfiles['paths']; - $filename = $attachedfiles['names']; - $mimetype = $attachedfiles['mimes']; - - // Send mail - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; - $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); - if ($mailfile->error) - { - $mesg='
'.$mailfile->error.'
'; - } - else - { - $result=$mailfile->sendfile(); - if ($result) - { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain " - - $error=0; - - // Initialisation donnees - $object->sendtoid = $sendtoid; - $object->actiontypecode = $actiontypecode; - $object->actionmsg = $actionmsg; - $object->actionmsg2 = $actionmsg2; - $object->fk_element = $object->id; - $object->elementtype = $object->element; - - // Appel des triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($db); - $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // Fin appel triggers - - if ($error) - { - dol_print_error($db); - } - else - { - // Redirect here - // This avoid sending mail twice if going out and then back to page - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg)); - exit; - } - } - else - { - $langs->load("other"); - $mesg='
'; - if ($mailfile->error) - { - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); - $mesg.='
'.$mailfile->error; - } - else - { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } - $mesg.='
'; - } - } - } - - else - { - $langs->load("other"); - $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').'
'; - dol_syslog('Recipient email is empty'); - } -/* } - else - { - $langs->load("errors"); - $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; - dol_syslog('Failed to read file: '.$file); - }*/ - } - else - { - $langs->load("other"); - $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
'; - dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.'); - } - - //$action = 'presend'; -} - -// Build document -elseif ($action == 'builddoc') -{ - // Save modele used - $object->fetch($id); - $object->fetch_thirdparty(); - if ($_REQUEST['model']) - { - $object->setDocModel($user, $_REQUEST['model']); - } - - $outputlangs = $langs; - if (! empty($_REQUEST['lang_id'])) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - $result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - else - { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); - exit; - } -} - -// Delete file in doc form -elseif ($action == 'remove_file') -{ - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - - if ($object->fetch($id)) - { - $object->fetch_thirdparty(); - $upload_dir = $conf->fournisseur->facture->dir_output . "/"; - $file = $upload_dir . '/' . GETPOST('file'); - $ret=dol_delete_file($file,0,0,0,$object); - if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); - else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); - } -} - -if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer) -{ - if ($action == 'addcontact') - { - $result = $object->fetch($id); - - if ($result > 0 && $id > 0) - { - $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); - $result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); - } - - if ($result >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else - { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $langs->load("errors"); - $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; - } - else - { - $mesg = '
'.$object->error.'
'; - } - } - } - - // bascule du statut d'un contact - else if ($action == 'swapstatut') - { - if ($object->fetch($id)) - { - $result=$object->swapContactStatus(GETPOST('ligne')); - } - else - { - dol_print_error($db); - } - } - - // Efface un contact - else if ($action == 'deletecontact') - { - $object->fetch($id); - $result = $object->delete_contact($_GET["lineid"]); - - if ($result >= 0) - { - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); - exit; - } - else { - dol_print_error($db); - } - } -} - - -/* - * View - */ - -$form = new Form($db); -$formfile = new FormFile($db); -$bankaccountstatic=new Account($db); - -llxHeader('','',''); - -// Mode creation -if ($action == 'create') -{ - print_fiche_titre($langs->trans('NewBill')); - - dol_htmloutput_mesg($mesg); - - $societe=''; - if ($_GET['socid']) - { - $societe=new Societe($db); - $societe->fetch($_GET['socid']); - } - - if (GETPOST('origin') && GETPOST('originid')) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = GETPOST('origin'); - - if ($element == 'project') - { - $projectid=GETPOST('originid'); - } - else if (in_array($element,array('order_supplier'))) - { - // For compatibility - if ($element == 'order') { - $element = $subelement = 'commande'; - } - if ($element == 'propal') { - dol_htmloutput_errors('',$errors); - $element = 'comm/propal'; $subelement = 'propal'; - } - if ($element == 'contract') { - $element = $subelement = 'contrat'; - } - if ($element == 'order_supplier') { - $element = 'fourn'; $subelement = 'fournisseur.commande'; - } - - require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'; - $classname = ucfirst($subelement); - if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; - $objectsrc = new $classname($db); - $objectsrc->fetch(GETPOST('originid')); - $objectsrc->fetch_thirdparty(); - - $projectid = (!empty($objectsrc->fk_project)?$object->fk_project:''); - //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); - - $soc = $objectsrc->client; - $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); - $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); - $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); - $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); - $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; - - $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); - $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp); - $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); - $datedue=($datetmp==''?-1:$datetmp); - } - } - else - { - $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); - $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp); - $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); - $datedue=($datetmp==''?-1:$datetmp); - } - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Ref - print ''; - - // Third party - print ''; - print ''; - - // Ref supplier - print ''; - print ''; - - print ''; - - // Label - print ''; - - // Date invoice - print ''; - - // Due date - print ''; - - print ''; - print ''; - print ''; - - if (is_object($objectsrc)) - { - print "\n"; - print "\n"; - print ''."\n"; - print ''."\n"; - print ''."\n"; - print ''; - print ''; - - $txt=$langs->trans($classname); - if ($classname=='CommandeFournisseur') $txt=$langs->trans("SupplierOrder"); - print ''; - print ''; - print '"; - if ($mysoc->country_code=='ES') - { - if ($mysoc->localtax1_assuj=="1") //Localtax1 RE - { - print '"; - } - - if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF - { - print '"; - } - } - print '"; - } - else - { - // TODO more bugs - if (1==2 && ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - for ($i = 1 ; $i < 9 ; $i++) - { - $value_qty = '1'; - $value_tauxtva = ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - } - } - - // Other options - $parameters=array(); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - - // Bouton "Create Draft" - print "
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Supplier').''; - - if ($_REQUEST['socid'] > 0) - { - print $societe->getNomUrl(1); - print ''; - } - else - { - print $form->select_company((empty($_GET['socid'])?'':$_GET['socid']),'socid','s.fournisseur = 1',1); - } - print '
'.$langs->trans('RefSupplier').'
'.$langs->trans('Type').''; - print ''."\n"; - - // Standard invoice - print ''."\n"; - - /* - // Deposit - print ''."\n"; - - // Proforma - if (! empty($conf->global->FACTURE_USE_PROFORMAT)) - { - print ''."\n"; - } - - // Replacement - print ''; - - // Credit note - print ''."\n"; - */ - print '
'; - print ''; - print ''; - $desc=$form->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $desc=$form->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $text=$langs->trans("InvoiceReplacementAsk").' '; - $text.=''; - $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); - print $desc; - print '
'; - print ''; - print ''; - $text=$langs->transnoentities("InvoiceAvoirAsk").' '; - // $text.=''; - $text.=''; - $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); - print $desc; - print '
'; - print '
'.$langs->trans('Label').'
'.$langs->trans('DateInvoice').''; - $form->select_date($dateinvoice,'','','','',"add",1,1); - print '
'.$langs->trans('DateMaxPayment').''; - $form->select_date($datedue,'ech','','','',"add",1,1); - print '
'.$langs->trans('NotePublic').'
'.$txt.''.$objectsrc->getNomUrl(1).'
'.$langs->trans('TotalHT').''.price($objectsrc->total_ht).'
'.$langs->trans('TotalVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1",$mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2",$mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('TotalTTC').''.price($objectsrc->total_ttc)."
 '.$langs->trans('Label').''.$langs->trans('PriceUHT').''.$langs->trans('VAT').''.$langs->trans('Qty').''.$langs->trans('PriceUTTC').'
'.$i.''; - print $form->load_tva('tauxtva'.$i,$value_tauxtva,$societe,$mysoc); - print '
\n"; - - print '
'; - - print "
\n"; - - - // Show origin lines - if (is_object($objectsrc)) - { - print '
'; - - $title=$langs->trans('ProductsAndServices'); - print_titre($title); - - print ''; - - $objectsrc->printOriginLinesList($hookmanager); - - print '
'; - } -} -else -{ - if ($id > 0) - { - /* *************************************************************************** */ - /* */ - /* Fiche en mode visu ou edition */ - /* */ - /* *************************************************************************** */ - - $now=dol_now(); - - $productstatic = new Product($db); - - $object->fetch($id); - - $societe = new Fournisseur($db); - $societe->fetch($object->socid); - - /* - * View card - */ - $head = facturefourn_prepare_head($object); - $titre=$langs->trans('SupplierInvoice'); - dol_fiche_head($head, 'card', $titre, 0, 'bill'); - - dol_htmloutput_mesg($mesg); - dol_htmloutput_errors('',$errors); - - // Confirmation de la suppression d'une ligne produit - if ($action == 'confirm_delete_line') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 1, 1); - if ($ret == 'html') print '
'; - } - - // Clone confirmation - if ($action == 'clone') - { - // Create an array for form - $formquestion=array( - //'text' => $langs->trans("ConfirmClone"), - //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1) - ); - // Paiement incomplet. On demande si motif = escompte ou autre - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes', 1); - if ($ret == 'html') print '
'; - } - - // Confirmation de la validation - if ($action == 'valid') - { - $formquestion=array(); - if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1)) - { - $langs->load("stocks"); - require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; - $formproduct=new FormProduct($db); - $formquestion=array( - //'text' => $langs->trans("ConfirmClone"), - //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), - //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), - array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))); - } - - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $object->ref), 'confirm_valid', $formquestion, 1, 1, 240); - if ($ret == 'html') print '
'; - } - - // Confirmation set paid - if ($action == 'paid') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1); - if ($ret == 'html') print '
'; - } - - // Confirmation de la suppression de la facture fournisseur - if ($action == 'delete') - { - $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1); - if ($ret == 'html') print '
'; - } - - - /** - * Invoice - */ - print ''; - - $linkback = ''.$langs->trans("BackToList").''; - - // Ref - print ''; - print "\n"; - - // Ref supplier - print ''; - - // Third party - print ''; - print ''; - - // Type - print ''; - - // Label - print ''; - print ''; - - /* - * List of payments - */ - $nbrows=7; $nbcols=2; - if (! empty($conf->projet->enabled)) $nbrows++; - if (! empty($conf->banque->enabled)) $nbcols++; - - // Local taxes - if ($mysoc->country_code=='ES') - { - if($mysoc->localtax1_assuj=="1") $nbrow++; - if($mysoc->localtax2_assuj=="1") $nbrow++; - } - - print ''; - - print ''; - - // Date - print ''; - - // Due date - print ''; - - // Status - $alreadypaid=$object->getSommePaiement(); - print ''; - - print ''; - print ''; - - // Amount Local Taxes - if ($mysoc->country_code=='ES') - { - if ($mysoc->localtax1_assuj=="1") //Localtax1 RE - { - print ''; - print ''; - print ''; - } - if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF - { - print ''; - print ''; - print ''; - } - } - print ''; - - // Project - if (! empty($conf->projet->enabled)) - { - $langs->load('projects'); - print ''; - print ''; - print ''; - } - - // Other options - $parameters=array('colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - - print '
'.$langs->trans("Ref").''; - print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref'); - print '
'.$form->editfieldkey("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; - print $form->editfieldval("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)); - print '
'.$langs->trans('Supplier').''.$societe->getNomUrl(1); - print '   ('.$langs->trans('OtherBills').')
'.$langs->trans('Type').''; - print $object->getLibType(); - if ($object->type == 1) - { - $facreplaced=new FactureFournisseur($db); - $facreplaced->fetch($object->fk_facture_source); - print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; - } - if ($object->type == 2) - { - $facusing=new FactureFournisseur($db); - $facusing->fetch($object->fk_facture_source); - print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')'; - } - - $facidavoir=$object->getListIdAvoirFromInvoice(); - if (count($facidavoir) > 0) - { - print ' ('.$langs->transnoentities("InvoiceHasAvoir"); - $i=0; - foreach($facidavoir as $id) - { - if ($i==0) print ' '; - else print ','; - $facavoir=new FactureFournisseur($db); - $facavoir->fetch($id); - print $facavoir->getNomUrl(1); - } - print ')'; - } - if (isset($facidnext) && $facidnext > 0) - { - $facthatreplace=new FactureFournisseur($db); - $facthatreplace->fetch($facidnext); - print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; - } - print '
'.$form->editfieldkey("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''.$form->editfieldval("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; - - $sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,'; - $sql.= ' c.libelle as paiement_type,'; - $sql.= ' pf.amount,'; - $sql.= ' ba.rowid as baid, ba.ref, ba.label'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; - $sql.= ' WHERE pf.fk_facturefourn = '.$object->id; - $sql.= ' ORDER BY p.datep, p.tms'; - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $i = 0; $totalpaye = 0; - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->banque->enabled)) print ''; - print ''; - print ''; - print ''; - - $var=true; - if ($num > 0) - { - while ($i < $num) - { - $objp = $db->fetch_object($result); - $var=!$var; - print ''; - print '\n"; - print ''; - if (! empty($conf->banque->enabled)) - { - $bankaccountstatic->id=$objp->baid; - $bankaccountstatic->ref=$objp->ref; - $bankaccountstatic->label=$objp->ref; - print ''; - } - print ''; - print ''; - print ''; - $totalpaye += $objp->amount; - $i++; - } - } - else - { - print ''; - } - - if ($object->paye == 0) - { - print ''; - print ''; - - $resteapayer = $object->total_ttc - $totalpaye; - - print ''; - print ''; - } - print '
'.$langs->trans('Payments').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')."'.$objp->paiement_type.' '.$objp->num_paiement.''; - print $bankaccountstatic->getNomUrl(1,'transactions'); - print ''.price($objp->amount).''; - if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) - { - print 'rowid.'">'; - print img_delete(); - print ''; - } - print '
'.$langs->trans("None").'
'.$langs->trans('AlreadyPaid').' :'.price($totalpaye).'
'.$langs->trans("Billed").' :'.price($object->total_ttc).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).'
'; - $db->free($result); - } - else - { - dol_print_error($db); - } - print '
'.$form->editfieldkey("Date",'datef',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker').''; - print $form->editfieldval("Date",'datef',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker'); - print '
'.$form->editfieldkey("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker').''; - print $form->editfieldval("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker'); - if ($action != 'editdate_lim_reglement' && $object->statut < 2 && $object->date_echeance && $object->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_warning($langs->trans('Late')); - print '
'.$langs->trans('Status').''.$object->getLibStatut(4,$alreadypaid).'
'.$langs->trans('AmountHT').''.price($object->total_ht).''.$langs->trans('Currency'.$conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva).''.$langs->trans('Currency'.$conf->currency).'
'.$langs->transcountry("AmountLT1",$mysoc->country_code).''.price($object->total_localtax1).''.$langs->trans("Currency".$conf->currency).'
'.$langs->transcountry("AmountLT2",$mysoc->country_code).''.price($object->total_localtax2).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc).''.$langs->trans('Currency'.$conf->currency).'
'; - - print ''; - if ($action != 'classify') - { - print ''; - } - print '
'; - print $langs->trans('Project'); - print 'id.'">'; - print img_edit($langs->trans('SetProject'),1); - print '
'; - - print '
'; - if ($action == 'classify') - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,'projectid'); - } - else - { - $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,'none'); - } - print '
'; - - if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) - { - print '
'; - $blocname = 'contacts'; - $title = $langs->trans('ContactsAddresses'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) - { - $colwidth=20; - $blocname = 'notes'; - $title = $langs->trans('Notes'); - include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; - } - - - /* - * Lines - */ - print '
'; - print ''; - $var=1; - $num=count($object->lines); - for ($i = 0; $i < $num; $i++) - { - if ($i == 0) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - - // Show product and description - $type=(! empty($object->lines[$i]->product_type)?$object->lines[$i]->product_type:(! empty($object->lines[$i]->fk_product_type)?$object->lines[$i]->fk_product_type:0)); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - $date_start=''; - $date_end=''; - if (! empty($object->lines[$i]->date_start)) - { - $date_start=$object->lines[$i]->date_start; - $type=1; - } - if (! empty($object->lines[$i]->date_end)) - { - $date_end=$object->lines[$i]->date_end; - $type=1; - } - - $var=!$var; - - // Edit line - if ($object->statut == 0 && $action == 'edit_line' && $_GET['etat'] == '0' && $_GET['lineid'] == $object->lines[$i]->rowid) - { - print 'lines[$i]->rowid.'" method="post">'; - print ''; - print ''; - print ''; - - // Show product and description - print ''; - - // VAT - print ''; - - // Unit price - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - print ''; - } - else // Affichage simple de la ligne - { - print ''; - - // Show product and description - print ''; - - // VAT - print ''; - - // Unit price - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - - print ''; - } - - } - - /* - * Form to add new line - */ - - if ($object->statut == 0 && $action != 'edit_line') - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Add free products/services form - print ''; - print ''; - print ''; - print ''; - - $var=true; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - // Ajout de produits/services predefinis - if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - $var=! $var; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - } - } - - print '
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('TotalHTShort').''.$langs->trans('TotalTTCShort').'  
'; - if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $object->lines[$i]->fk_product) - { - print ''; - $product_static=new ProductFournisseur($db); - $product_static->fetch($object->lines[$i]->fk_product); - $text=$product_static->getNomUrl(1); - $text.= ' - '.$product_static->libelle; - print $text; - print '
'; - } - else - { - $forceall=1; // For suppliers, we always show all types - print $form->select_type_of_lines($object->lines[$i]->product_type,'type',1); - if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) - || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '
'; - } - - if (is_object($hookmanager)) - { - $parameters=array('fk_parent_line'=>$line->fk_parent_line, 'line'=>$object->lines[$i],'var'=>$var,'num'=>$num,'i'=>$i); - $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$object,$action); - } - - // Description - Editor wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $nbrows=ROWS_2; - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('desc',$object->lines[$i]->description,'',128,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); - $doleditor->Create(); - print '
'; - print $form->load_tva('tauxtva',$object->lines[$i]->tva_tx,$societe,$mysoc); - print '%  '; - print '
'; - if ($object->lines[$i]->fk_product) - { - print ''; // ancre pour retourner sur la ligne - - $product_static=new ProductFournisseur($db); - $product_static->fetch($object->lines[$i]->fk_product); - $text=$product_static->getNomUrl(1); - $text.= ' - '.$product_static->libelle; - $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($object->lines[$i]->description)); - print $form->textwithtooltip($text,$description,3,'','',$i); - - // Show range - print_date_range($date_start,$date_end); - - // Add description in form - if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print ($object->lines[$i]->description && $object->lines[$i]->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($object->lines[$i]->description):''; - } - - // Description - Editor wysiwyg - if (! $object->lines[$i]->fk_product) - { - if ($type==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '.nl2br($object->lines[$i]->description); - - // Show range - print_date_range($date_start,$date_end); - } - print '
'.vatrate($object->lines[$i]->tva_tx).'%'.price($object->lines[$i]->pu_ht,'MU').''.($object->lines[$i]->pu_ttc?price($object->lines[$i]->pu_ttc,'MU'):' ').''.$object->lines[$i]->qty.''.(($object->lines[$i]->remise_percent > 0)?$object->lines[$i]->remise_percent.'%':'').''.price($object->lines[$i]->total_ht).''.price($object->lines[$i]->total_ttc).''; - if ($object->statut == 0) print 'lines[$i]->rowid.'">'.img_edit().''; - else print ' '; - print ''; - if ($object->statut == 0) print 'lines[$i]->rowid.'">'.img_delete().''; - else print ' '; - print '
'; - print ''; // ancre - print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').'     
'; - - $forceall=1; // For suppliers, we always show all types - print $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,0,$forceall); - if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) - || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '
'; - - if (is_object($hookmanager)) - { - $parameters=array(); - $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); - } - - // Editor wysiwyg - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $nbrows=ROWS_2; - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('dp_desc',GETPOST("dp_desc"),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); - $doleditor->Create(); - - print '
'; - print $form->load_tva('tauxtva',(GETPOST('tauxtva')?GETPOST('tauxtva'):-1),$societe,$mysoc); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '%  
'; - print $langs->trans("AddNewLine").' - '; - if (! empty($conf->service->enabled)) - { - print $langs->trans('RecordedProductsAndServices'); - } - else - { - print $langs->trans('RecordedProducts'); - } - print ''.$langs->trans('Qty').'   
'; - - $ajaxoptions=array( - 'update' => array('pqty' => 'qty', 'p_remise_percent' => 'discount'), - 'disabled' => 'addPredefinedProductButton', - 'error' => $langs->trans("NoPriceDefinedForThisSupplier") - ); - $form->select_produits_fournisseurs($object->socid, '', 'idprodfournprice', '', '', $ajaxoptions); - - if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '
'; - - if (is_object($hookmanager)) - { - $parameters=array('htmlname'=>'idprodfournprice'); - $reshook=$hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action); - } - - $nbrows=ROWS_2; - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor = new DolEditor('np_desc', GETPOST('np_desc'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, $nbrows, 70); - $doleditor->Create(); - - print '
%  
'; - - print ''; - - if ($action != 'presend') - { - - /* - * Boutons actions - */ - - print '
'; - - // Reopen a standard paid invoice - if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) - { - if (! $facidnext && $object->close_code != 'replaced') // Not replaced by another invoice - { - print ''.$langs->trans('ReOpen').''; - } - else - { - print ''.$langs->trans('ReOpen').''; - } - } - - // Send by mail - if (($object->statut == 1 || $object->statut == 2)) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; - } - - - //Make payments - if ($action != 'edit' && $object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) - { - print ''.$langs->trans('DoPayment').''; - } - - //Classify paid - if ($action != 'edit' && $object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) - { - print ''.$langs->trans('ClassifyPaid').''; - - //print ''.$langs->trans('ClassifyPaid').''; - } - - //Validate - if ($action != 'edit' && $object->statut == 0) - { - if (count($object->lines)) - { - if ($user->rights->fournisseur->facture->valider) - { - print ''.$langs->trans('Validate').''; - } - else - { - print ''.$langs->trans('Validate').''; - } - } - } - - //Clone - if ($action != 'edit' && $user->rights->fournisseur->facture->creer) - { - print 'socid.'">'.$langs->trans('ToClone').''; - } - - //Delete - if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer) - { - print ''.$langs->trans('Delete').''; - } - print '
'; - - if ($action != 'edit') - { - print '
'; - print ''; // ancre - - /* - * Documents generes - */ - - $ref=dol_sanitizeFileName($object->ref); - $subdir = get_exdir($object->id,2).$ref; - $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$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:''); - - print '
'; - print $formfile->showdocuments('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,0,0,'','','',$societe->default_lang); - $somethingshown=$formfile->numoffiles; - - /* - * Linked object block - */ - $somethingshown=$object->showLinkedObjectBlock(); - - print '
'; - print '
'; - - // List of actions on element - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; - $formactions=new FormActions($db); - $somethingshown=$formactions->showactions($object,'invoice_supplier',$socid); - - print '
'; - } - } - /* - * Show mail form - */ - if ($action == 'presend') - { - $ref = dol_sanitizeFileName($object->ref); - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref); - $file=$fileparams['fullname']; - - // Build document if it not exists - if (! $file || ! is_readable($file)) - { - // Define output language - $outputlangs = $langs; - $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - - $result=supplier_invoice_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); - if ($result <= 0) - { - dol_print_error($db,$result); - exit; - } - $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref); - $file=$fileparams['fullname']; - } - - print '
'; - print_titre($langs->trans('SendBillByMail')); - - // Cree l'objet formulaire mail - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - $formmail->fromtype = 'user'; - $formmail->fromid = $user->id; - $formmail->fromname = $user->getFullName($langs); - $formmail->frommail = $user->email; - $formmail->withfrom=1; - $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; - $formmail->withtosocid=$soc->id; - $formmail->withtocc=1; - $formmail->withtoccsocid=0; - $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; - $formmail->withtocccsocid=0; - $formmail->withtopic=$langs->trans('SendBillRef','__FACREF__'); - $formmail->withfile=2; - $formmail->withbody=1; - $formmail->withdeliveryreceipt=1; - $formmail->withcancel=1; - // Tableau des substitutions - $formmail->substit['__FACREF__']=$object->ref; - $formmail->substit['__SIGNATURE__']=$user->signature; - $formmail->substit['__PERSONALIZED__']=''; - // Tableau des parametres complementaires - $formmail->param['action']='send'; - $formmail->param['models']='invoice_supplier_send'; - $formmail->param['facid']=$object->id; - $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - - // Init list of files - if (GETPOST("mode")=='init') - { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); - } - - // Show form - $formmail->show_form(); - - print '
'; - } - } -} - - -// End of page -llxFooter(); -$db->close(); -?> + $result=$object->update($user); + if ($result < 0) dol_print_error($db,$object->error); +} +elseif ($action == 'setnote_public' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES)); + if ($result < 0) dol_print_error($db,$object->error); +} +elseif ($action == 'setnote' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES)); + if ($result < 0) dol_print_error($db,$object->error); +} + +// Delete payment +elseif ($action == 'deletepaiement') +{ + $object->fetch($id); + if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + { + $paiementfourn = new PaiementFourn($db); + $paiementfourn->fetch(GETPOST('paiement_id')); + $result=$paiementfourn->delete(); + if ($result < 0) $mesg='
'.$paiementfourn->error.'
'; + } +} + +// Create +elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) +{ + $error=0; + + $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); + $datedue=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); + + if ($datefacture == '') + { + $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'
'; + $action='create'; + $_GET['socid']=$_POST['socid']; + $error++; + } + if (! GETPOST('facnumber')) + { + $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'
'; + $action='create'; + $_GET['socid']=$_POST['socid']; + $error++; + } + + if (! $error) + { + $db->begin(); + + // Creation facture + $object->ref = $_POST['facnumber']; + $object->socid = $_POST['socid']; + $object->libelle = $_POST['libelle']; + $object->date = $datefacture; + $object->date_echeance = $datedue; + $object->note_public = $_POST['note']; + + // If creation from another object of another module + if ($_POST['origin'] && $_POST['originid']) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = $_POST['origin']; + /*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + }*/ + + // For compatibility + if ($element == 'order') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + $element = 'comm/propal'; $subelement = 'propal'; + } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } + if ($element == 'order_supplier') { + $element = 'fourn'; $subelement = 'fournisseur.commande'; + } + + $object->origin = $_POST['origin']; + $object->origin_id = $_POST['originid']; + + $id = $object->create($user); + + // Add lines + if ($id > 0) + { + require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'; + $classname = ucfirst($subelement); + if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; + $srcobject = new $classname($db); + + $result=$srcobject->fetch($_POST['originid']); + if ($result > 0) + { + $lines = $srcobject->lines; + if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); + + $num=count($lines); + for ($i = 0; $i < $num; $i++) + { + $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); + $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + + // Dates + // TODO mutualiser + $date_start=$lines[$i]->date_debut_prevue; + if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel; + if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start; + $date_end=$lines[$i]->date_fin_prevue; + if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel; + if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end; + + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->qty, + $lines[$i]->fk_product, + $lines[$i]->remise_percent, + $date_start, + $date_end, + 0, + $lines[$i]->info_bits, + 'HT', + $product_type + ); + + if ($result < 0) + { + $error++; + break; + } + } + } + else + { + $error++; + } + } + else + { + $error++; + } + } + // If some invoice's lines already known + else + { + $id = $object->create($user); + if ($id < 0) + { + $error++; + } + + if (! $error) + { + for ($i = 1 ; $i < 9 ; $i++) + { + $label = $_POST['label'.$i]; + $amountht = price2num($_POST['amount'.$i]); + $amountttc = price2num($_POST['amountttc'.$i]); + $tauxtva = price2num($_POST['tauxtva'.$i]); + $qty = $_POST['qty'.$i]; + $fk_product = $_POST['fk_product'.$i]; + if ($label) + { + if ($amountht) + { + $price_base='HT'; $amount=$amountht; + } + else + { + $price_base='TTC'; $amount=$amountttc; + } + $atleastoneline=1; + + $product=new Product($db); + $product->fetch($_POST['idprod'.$i]); + + $ret=$object->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base); + if ($ret < 0) $error++; + } + } + } + } + + if ($error) + { + $langs->load("errors"); + $db->rollback(); + $mesg='
'.$langs->trans($object->error).'
'; + $action='create'; + $_GET['socid']=$_POST['socid']; + } + else + { + $db->commit(); + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } + } +} + +// Modification d'une ligne +elseif ($action == 'update_line') +{ + if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification + { + $object->fetch($id); + $object->fetch_thirdparty(); + + if ($_POST['puht']) + { + $pu=$_POST['puht']; + $price_base_type='HT'; + } + if ($_POST['puttc']) + { + $pu=$_POST['puttc']; + $price_base_type='TTC'; + } + + if (GETPOST('idprod')) + { + $prod = new Product($db); + $prod->fetch($_POST['idprod']); + $label = $prod->description; + if (trim($_POST['desc']) != trim($label)) $label=$_POST['desc']; + + $type = $prod->type; + } + else + { + + $label = $_POST['desc']; + $type = $_POST["type"]?$_POST["type"]:0; + + } + + $localtax1tx= get_localtax($_POST['tauxtva'], 1, $object->thirdparty); + $localtax2tx= get_localtax($_POST['tauxtva'], 2, $object->thirdparty); + $remise_percent=GETPOST('remise_percent'); + + $result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1tx, $localtax2tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent); + if ($result >= 0) + { + unset($_POST['label']); + } + } +} + +elseif ($action == 'addline') +{ + $ret=$object->fetch($id); + if ($ret < 0) + { + dol_print_error($db,$object->error); + exit; + } + $ret=$object->fetch_thirdparty(); + + if ($_POST['idprodfournprice']) // > 0 or -1 + { + $product=new Product($db); + $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']); // Just to see if a price exists for the quantity. Not used to found vat + + if ($idprod > 0) + { + $result=$product->fetch($idprod); + + // cas special pour lequel on a les meme reference que le fournisseur + // $label = '['.$product->ref.'] - '. $product->libelle; + $label = $product->description; + $label.= $product->description && $_POST['np_desc'] ? "\n" : ""; + $label.= $_POST['np_desc']; + + $tvatx=get_default_tva($object->thirdparty, $mysoc, $product->id, $_POST['idprodfournprice']); + + $localtax1tx= get_localtax($tvatx, 1, $object->thirdparty); + $localtax2tx= get_localtax($tvatx, 2, $object->thirdparty); + $remise_percent=GETPOST('remise_percent'); + $type = $product->type; + + $result=$object->addline($label, $product->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $_POST['qty'], $idprod, $remise_percent); + + } + if ($idprod == -1) + { + // Quantity too low + $langs->load("errors"); + $mesg='
'.$langs->trans("ErrorQtyTooLowForThisSupplier").'
'; + } + } + else + { + $tauxtva = price2num($_POST['tauxtva']); + $localtax1tx= get_localtax($tauxtva, 1, $object->thirdparty); + $localtax2tx= get_localtax($tauxtva, 2, $object->thirdparty); + $remise_percent=GETPOST('remise_percent'); + + if (! $_POST['dp_desc']) + { + $mesg='
'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")).'
'; + } + else + { + $type = $_POST["type"]; + if (! empty($_POST['amount'])) + { + $ht = price2num($_POST['amount']); + $price_base_type = 'HT'; + + //$desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0) + $result=$object->addline($_POST['dp_desc'], $ht, $tauxtva, $localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, 0, $price_base_type, $type); + } + else + { + $ttc = price2num($_POST['amountttc']); + $ht = $ttc / (1 + ($tauxtva / 100)); + $price_base_type = 'HT'; + $result=$object->addline($_POST['dp_desc'], $ht, $tauxtva,$localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, 0, $price_base_type, $type); + } + } + } + + //print "xx".$tva_tx; exit; + if ($result > 0) + { + // Define output language + $outputlangs = $langs; + $newlang=GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['idprodfournprice']); + unset($_POST['remise_percent']); + unset($_POST['dp_desc']); + unset($_POST['np_desc']); + unset($_POST['pu']); + unset($_POST['tva_tx']); + unset($_POST['label']); + unset($localtax1_tx); + unset($localtax2_tx); + } + else if (empty($mesg)) + { + $mesg='
'.$object->error.'
'; + } + + $action = ''; +} + +elseif ($action == 'classin') +{ + $object->fetch($id); + $result=$object->setProject($_POST['projectid']); +} + + +// Set invoice to draft status +elseif ($action == 'edit' && $user->rights->fournisseur->facture->creer) +{ + $object->fetch($id); + + $totalpaye = $object->getSommePaiement(); + $resteapayer = $object->total_ttc - $totalpaye; + + // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees + //$ventilExportCompta = $object->getVentilExportCompta(); + + // On verifie si aucun paiement n'a ete effectue + if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) + { + $object->set_draft($user); + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + } +} + +// Set invoice to validated/unpaid status +elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer) +{ + $result = $object->fetch($id); + if ($object->statut == 2 + || ($object->statut == 3 && $object->close_code != 'replaced')) + { + $result = $object->set_unpaid($user); + if ($result > 0) + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit; + } + else + { + $mesg='
'.$object->error.'
'; + } + } +} + +// Add file in email form +if (GETPOST('addfile')) +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory TODO Use a dedicated directory for temp mails files + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; + + dol_add_file_process($upload_dir_tmp,0,0); + $action='presend'; +} + +// Remove file in email form +if (! empty($_POST['removedfile'])) +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + // Set tmp user directory + $vardir=$conf->user->dir_output."/".$user->id; + $upload_dir_tmp = $vardir.'/temp'; + + // TODO Delete only files that was uploaded from email form + dol_remove_file_process($_POST['removedfile'],0); + $action='presend'; +} + +// Send mail +if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) +{ + $langs->load('mails'); + + $object->fetch($id); + $result=$object->fetch_thirdparty(); + if ($result > 0) + { +// $ref = dol_sanitizeFileName($object->ref); +// $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf'; + +// if (is_readable($file)) +// { + if ($_POST['sendto']) + { + // Le destinataire a ete fourni via le champ libre + $sendto = $_POST['sendto']; + $sendtoid = 0; + } + elseif ($_POST['receiver'] != '-1') + { + // Recipient was provided from combo list + if ($_POST['receiver'] == 'thirdparty') // Id of third party + { + $sendto = $object->client->email; + $sendtoid = 0; + } + else // Id du contact + { + $sendto = $object->client->contact_get_property($_POST['receiver'],'email'); + $sendtoid = $_POST['receiver']; + } + } + + if (dol_strlen($sendto)) + { + $langs->load("commercial"); + + $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>'; + $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; + $message = $_POST['message']; + $sendtocc = $_POST['sendtocc']; + $deliveryreceipt = $_POST['deliveryreceipt']; + + if ($action == 'send') + { + if (dol_strlen($_POST['subject'])) $subject=$_POST['subject']; + else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref; + $actiontypecode='AC_SUP_ORD'; + $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n"; + if ($message) + { + $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n"; + $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n"; + $actionmsg.=$message; + } + $actionmsg2=$langs->transnoentities('Action'.$actiontypecode); + } + + // Create form object + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + + $attachedfiles=$formmail->get_attached_files(); + $filepath = $attachedfiles['paths']; + $filename = $attachedfiles['names']; + $mimetype = $attachedfiles['mimes']; + + // Send mail + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt); + if ($mailfile->error) + { + $mesg='
'.$mailfile->error.'
'; + } + else + { + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain " + + $error=0; + + // Initialisation donnees + $object->sendtoid = $sendtoid; + $object->actiontypecode = $actiontypecode; + $object->actionmsg = $actionmsg; + $object->actionmsg2 = $actionmsg2; + $object->fk_element = $object->id; + $object->elementtype = $object->element; + + // Appel des triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($db); + $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf); + if ($result < 0) { + $error++; $this->errors=$interface->errors; + } + // Fin appel triggers + + if ($error) + { + dol_print_error($db); + } + else + { + // Redirect here + // This avoid sending mail twice if going out and then back to page + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg)); + exit; + } + } + else + { + $langs->load("other"); + $mesg='
'; + if ($mailfile->error) + { + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.='
'.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.='
'; + } + } + } + + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorMailRecipientIsEmpty').'
'; + dol_syslog('Recipient email is empty'); + } +/* } + else + { + $langs->load("errors"); + $mesg='
'.$langs->trans('ErrorCantReadFile',$file).'
'; + dol_syslog('Failed to read file: '.$file); + }*/ + } + else + { + $langs->load("other"); + $mesg='
'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'
'; + dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.'); + } + + //$action = 'presend'; +} + +// Build document +elseif ($action == 'builddoc') +{ + // Save modele used + $object->fetch($id); + $object->fetch_thirdparty(); + if ($_REQUEST['model']) + { + $object->setDocModel($user, $_REQUEST['model']); + } + + $outputlangs = $langs; + if (! empty($_REQUEST['lang_id'])) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + $result=supplier_invoice_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + else + { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc')); + exit; + } +} + +// Delete file in doc form +elseif ($action == 'remove_file') +{ + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + if ($object->fetch($id)) + { + $object->fetch_thirdparty(); + $upload_dir = $conf->fournisseur->facture->dir_output . "/"; + $file = $upload_dir . '/' . GETPOST('file'); + $ret=dol_delete_file($file,0,0,0,$object); + if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile'))); + else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors'); + } +} + +if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer) +{ + if ($action == 'addcontact') + { + $result = $object->fetch($id); + + if ($result > 0 && $id > 0) + { + $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); + $result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); + } + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'
'; + } + else + { + $mesg = '
'.$object->error.'
'; + } + } + } + + // bascule du statut d'un contact + else if ($action == 'swapstatut') + { + if ($object->fetch($id)) + { + $result=$object->swapContactStatus(GETPOST('ligne')); + } + else + { + dol_print_error($db); + } + } + + // Efface un contact + else if ($action == 'deletecontact') + { + $object->fetch($id); + $result = $object->delete_contact($_GET["lineid"]); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + dol_print_error($db); + } + } +} + + +/* + * View + */ + +$form = new Form($db); +$formfile = new FormFile($db); +$bankaccountstatic=new Account($db); + +llxHeader('','',''); + +// Mode creation +if ($action == 'create') +{ + print_fiche_titre($langs->trans('NewBill')); + + dol_htmloutput_mesg($mesg); + + $societe=''; + if ($_GET['socid']) + { + $societe=new Societe($db); + $societe->fetch($_GET['socid']); + } + + if (GETPOST('origin') && GETPOST('originid')) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = GETPOST('origin'); + + if ($element == 'project') + { + $projectid=GETPOST('originid'); + } + else if (in_array($element,array('order_supplier'))) + { + // For compatibility + if ($element == 'order') { + $element = $subelement = 'commande'; + } + if ($element == 'propal') { + dol_htmloutput_errors('',$errors); + $element = 'comm/propal'; $subelement = 'propal'; + } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } + if ($element == 'order_supplier') { + $element = 'fourn'; $subelement = 'fournisseur.commande'; + } + + require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'; + $classname = ucfirst($subelement); + if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; + $objectsrc = new $classname($db); + $objectsrc->fetch(GETPOST('originid')); + $objectsrc->fetch_thirdparty(); + + $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); + //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); + + $soc = $objectsrc->client; + $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); + $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); + $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0)); + $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0)); + $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0; + + $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); + $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp); + $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); + $datedue=($datetmp==''?-1:$datetmp); + } + } + else + { + $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); + $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp); + $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']); + $datedue=($datetmp==''?-1:$datetmp); + } + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Ref + print ''; + + // Third party + print ''; + print ''; + + // Ref supplier + print ''; + print ''; + + print ''; + + // Label + print ''; + + // Date invoice + print ''; + + // Due date + print ''; + + print ''; + print ''; + print ''; + + if (is_object($objectsrc)) + { + print "\n"; + print "\n"; + print ''."\n"; + print ''."\n"; + print ''."\n"; + print ''; + print ''; + + $txt=$langs->trans($classname); + if ($classname=='CommandeFournisseur') $txt=$langs->trans("SupplierOrder"); + print ''; + print ''; + print '"; + if ($mysoc->country_code=='ES') + { + if ($mysoc->localtax1_assuj=="1") //Localtax1 RE + { + print '"; + } + + if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF + { + print '"; + } + } + print '"; + } + else + { + // TODO more bugs + if (1==2 && ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + for ($i = 1 ; $i < 9 ; $i++) + { + $value_qty = '1'; + $value_tauxtva = ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + } + + // Other options + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + // Bouton "Create Draft" + print "
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Supplier').''; + + if ($_REQUEST['socid'] > 0) + { + print $societe->getNomUrl(1); + print ''; + } + else + { + print $form->select_company((empty($_GET['socid'])?'':$_GET['socid']),'socid','s.fournisseur = 1',1); + } + print '
'.$langs->trans('RefSupplier').'
'.$langs->trans('Type').''; + print ''."\n"; + + // Standard invoice + print ''."\n"; + + /* + // Deposit + print ''."\n"; + + // Proforma + if (! empty($conf->global->FACTURE_USE_PROFORMAT)) + { + print ''."\n"; + } + + // Replacement + print ''; + + // Credit note + print ''."\n"; + */ + print '
'; + print ''; + print ''; + $desc=$form->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); + print $desc; + print '
'; + print ''; + print ''; + $desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); + print $desc; + print '
'; + print ''; + print ''; + $desc=$form->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); + print $desc; + print '
'; + print ''; + print ''; + $text=$langs->trans("InvoiceReplacementAsk").' '; + $text.=''; + $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1); + print $desc; + print '
'; + print ''; + print ''; + $text=$langs->transnoentities("InvoiceAvoirAsk").' '; + // $text.=''; + $text.=''; + $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1); + print $desc; + print '
'; + print '
'.$langs->trans('Label').'
'.$langs->trans('DateInvoice').''; + $form->select_date($dateinvoice,'','','','',"add",1,1); + print '
'.$langs->trans('DateMaxPayment').''; + $form->select_date($datedue,'ech','','','',"add",1,1); + print '
'.$langs->trans('NotePublic').'
'.$txt.''.$objectsrc->getNomUrl(1).'
'.$langs->trans('TotalHT').''.price($objectsrc->total_ht).'
'.$langs->trans('TotalVAT').''.price($objectsrc->total_tva)."
'.$langs->transcountry("AmountLT1",$mysoc->country_code).''.price($objectsrc->total_localtax1)."
'.$langs->transcountry("AmountLT2",$mysoc->country_code).''.price($objectsrc->total_localtax2)."
'.$langs->trans('TotalTTC').''.price($objectsrc->total_ttc)."
 '.$langs->trans('Label').''.$langs->trans('PriceUHT').''.$langs->trans('VAT').''.$langs->trans('Qty').''.$langs->trans('PriceUTTC').'
'.$i.''; + print $form->load_tva('tauxtva'.$i,$value_tauxtva,$societe,$mysoc); + print '
\n"; + + print '
'; + + print "
\n"; + + + // Show origin lines + if (is_object($objectsrc)) + { + print '
'; + + $title=$langs->trans('ProductsAndServices'); + print_titre($title); + + print ''; + + $objectsrc->printOriginLinesList($hookmanager); + + print '
'; + } +} +else +{ + if ($id > 0) + { + /* *************************************************************************** */ + /* */ + /* Fiche en mode visu ou edition */ + /* */ + /* *************************************************************************** */ + + $now=dol_now(); + + $productstatic = new Product($db); + + $object->fetch($id); + + $societe = new Fournisseur($db); + $societe->fetch($object->socid); + + /* + * View card + */ + $head = facturefourn_prepare_head($object); + $titre=$langs->trans('SupplierInvoice'); + dol_fiche_head($head, 'card', $titre, 0, 'bill'); + + dol_htmloutput_mesg($mesg); + dol_htmloutput_errors('',$errors); + + // Confirmation de la suppression d'une ligne produit + if ($action == 'confirm_delete_line') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 1, 1); + if ($ret == 'html') print '
'; + } + + // Clone confirmation + if ($action == 'clone') + { + // Create an array for form + $formquestion=array( + //'text' => $langs->trans("ConfirmClone"), + //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1) + ); + // Paiement incomplet. On demande si motif = escompte ou autre + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes', 1); + if ($ret == 'html') print '
'; + } + + // Confirmation de la validation + if ($action == 'valid') + { + $formquestion=array(); + if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1)) + { + $langs->load("stocks"); + require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; + $formproduct=new FormProduct($db); + $formquestion=array( + //'text' => $langs->trans("ConfirmClone"), + //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1), + //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1), + array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))); + } + + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $object->ref), 'confirm_valid', $formquestion, 1, 1, 240); + if ($ret == 'html') print '
'; + } + + // Confirmation set paid + if ($action == 'paid') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1); + if ($ret == 'html') print '
'; + } + + // Confirmation de la suppression de la facture fournisseur + if ($action == 'delete') + { + $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1); + if ($ret == 'html') print '
'; + } + + + /** + * Invoice + */ + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + print "\n"; + + // Ref supplier + print ''; + + // Third party + print ''; + print ''; + + // Type + print ''; + + // Label + print ''; + print ''; + + /* + * List of payments + */ + $nbrows=7; $nbcols=2; + if (! empty($conf->projet->enabled)) $nbrows++; + if (! empty($conf->banque->enabled)) $nbcols++; + + // Local taxes + if ($mysoc->country_code=='ES') + { + if($mysoc->localtax1_assuj=="1") $nbrow++; + if($mysoc->localtax2_assuj=="1") $nbrow++; + } + + print ''; + + print ''; + + // Date + print ''; + + // Due date + print ''; + + // Status + $alreadypaid=$object->getSommePaiement(); + print ''; + + print ''; + print ''; + + // Amount Local Taxes + if ($mysoc->country_code=='ES') + { + if ($mysoc->localtax1_assuj=="1") //Localtax1 RE + { + print ''; + print ''; + print ''; + } + if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF + { + print ''; + print ''; + print ''; + } + } + print ''; + + // Project + if (! empty($conf->projet->enabled)) + { + $langs->load('projects'); + print ''; + print ''; + print ''; + } + + // Other options + $parameters=array('colspan' => ' colspan="3"'); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref'); + print '
'.$form->editfieldkey("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; + print $form->editfieldval("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)); + print '
'.$langs->trans('Supplier').''.$societe->getNomUrl(1); + print '   ('.$langs->trans('OtherBills').')
'.$langs->trans('Type').''; + print $object->getLibType(); + if ($object->type == 1) + { + $facreplaced=new FactureFournisseur($db); + $facreplaced->fetch($object->fk_facture_source); + print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')'; + } + if ($object->type == 2) + { + $facusing=new FactureFournisseur($db); + $facusing->fetch($object->fk_facture_source); + print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')'; + } + + $facidavoir=$object->getListIdAvoirFromInvoice(); + if (count($facidavoir) > 0) + { + print ' ('.$langs->transnoentities("InvoiceHasAvoir"); + $i=0; + foreach($facidavoir as $id) + { + if ($i==0) print ' '; + else print ','; + $facavoir=new FactureFournisseur($db); + $facavoir->fetch($id); + print $facavoir->getNomUrl(1); + } + print ')'; + } + if (isset($facidnext) && $facidnext > 0) + { + $facthatreplace=new FactureFournisseur($db); + $facthatreplace->fetch($facidnext); + print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')'; + } + print '
'.$form->editfieldkey("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''.$form->editfieldval("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).''; + + $sql = 'SELECT p.datep as dp, p.num_paiement, p.rowid, p.fk_bank,'; + $sql.= ' c.libelle as paiement_type,'; + $sql.= ' pf.amount,'; + $sql.= ' ba.rowid as baid, ba.ref, ba.label'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid'; + $sql.= ' WHERE pf.fk_facturefourn = '.$object->id; + $sql.= ' ORDER BY p.datep, p.tms'; + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; $totalpaye = 0; + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; + print ''; + print ''; + print ''; + + $var=true; + if ($num > 0) + { + while ($i < $num) + { + $objp = $db->fetch_object($result); + $var=!$var; + print ''; + print '\n"; + print ''; + if (! empty($conf->banque->enabled)) + { + $bankaccountstatic->id=$objp->baid; + $bankaccountstatic->ref=$objp->ref; + $bankaccountstatic->label=$objp->ref; + print ''; + } + print ''; + print ''; + print ''; + $totalpaye += $objp->amount; + $i++; + } + } + else + { + print ''; + } + + if ($object->paye == 0) + { + print ''; + print ''; + + $resteapayer = $object->total_ttc - $totalpaye; + + print ''; + print ''; + } + print '
'.$langs->trans('Payments').''.$langs->trans('Type').''.$langs->trans('BankAccount').''.$langs->trans('Amount').' 
'.img_object($langs->trans('ShowPayment'),'payment').' '.dol_print_date($db->jdate($objp->dp),'day')."'.$objp->paiement_type.' '.$objp->num_paiement.''; + print $bankaccountstatic->getNomUrl(1,'transactions'); + print ''.price($objp->amount).''; + if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + { + print 'rowid.'">'; + print img_delete(); + print ''; + } + print '
'.$langs->trans("None").'
'.$langs->trans('AlreadyPaid').' :'.price($totalpaye).'
'.$langs->trans("Billed").' :'.price($object->total_ttc).'
'.$langs->trans('RemainderToPay').' :'.price($resteapayer).'
'; + $db->free($result); + } + else + { + dol_print_error($db); + } + print '
'.$form->editfieldkey("Date",'datef',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker').''; + print $form->editfieldval("Date",'datef',$object->datep,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker'); + print '
'.$form->editfieldkey("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker').''; + print $form->editfieldval("DateMaxPayment",'date_lim_reglement',$object->date_echeance,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer && $object->getSommePaiement() <= 0),'datepicker'); + if ($action != 'editdate_lim_reglement' && $object->statut < 2 && $object->date_echeance && $object->date_echeance < ($now - $conf->facture->fournisseur->warning_delay)) print img_warning($langs->trans('Late')); + print '
'.$langs->trans('Status').''.$object->getLibStatut(4,$alreadypaid).'
'.$langs->trans('AmountHT').''.price($object->total_ht).''.$langs->trans('Currency'.$conf->currency).'
'.$langs->trans('AmountVAT').''.price($object->total_tva).''.$langs->trans('Currency'.$conf->currency).'
'.$langs->transcountry("AmountLT1",$mysoc->country_code).''.price($object->total_localtax1).''.$langs->trans("Currency".$conf->currency).'
'.$langs->transcountry("AmountLT2",$mysoc->country_code).''.price($object->total_localtax2).''.$langs->trans("Currency".$conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc).''.$langs->trans('Currency'.$conf->currency).'
'; + + print ''; + if ($action != 'classify') + { + print ''; + } + print '
'; + print $langs->trans('Project'); + print 'id.'">'; + print img_edit($langs->trans('SetProject'),1); + print '
'; + + print '
'; + if ($action == 'classify') + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,'projectid'); + } + else + { + $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,'none'); + } + print '
'; + + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) + { + print '
'; + $blocname = 'contacts'; + $title = $langs->trans('ContactsAddresses'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB)) + { + $colwidth=20; + $blocname = 'notes'; + $title = $langs->trans('Notes'); + include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php'; + } + + + /* + * Lines + */ + print '
'; + print ''; + $var=1; + $num=count($object->lines); + for ($i = 0; $i < $num; $i++) + { + if ($i == 0) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + + // Show product and description + $type=(! empty($object->lines[$i]->product_type)?$object->lines[$i]->product_type:(! empty($object->lines[$i]->fk_product_type)?$object->lines[$i]->fk_product_type:0)); + // Try to enhance type detection using date_start and date_end for free lines where type + // was not saved. + $date_start=''; + $date_end=''; + if (! empty($object->lines[$i]->date_start)) + { + $date_start=$object->lines[$i]->date_start; + $type=1; + } + if (! empty($object->lines[$i]->date_end)) + { + $date_end=$object->lines[$i]->date_end; + $type=1; + } + + $var=!$var; + + // Edit line + if ($object->statut == 0 && $action == 'edit_line' && $_GET['etat'] == '0' && $_GET['lineid'] == $object->lines[$i]->rowid) + { + print 'lines[$i]->rowid.'" method="post">'; + print ''; + print ''; + print ''; + + // Show product and description + print ''; + + // VAT + print ''; + + // Unit price + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print ''; + } + else // Affichage simple de la ligne + { + print ''; + + // Show product and description + print ''; + + // VAT + print ''; + + // Unit price + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + } + + } + + /* + * Form to add new line + */ + + if ($object->statut == 0 && $action != 'edit_line') + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Add free products/services form + print ''; + print ''; + print ''; + print ''; + + $var=true; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + // Ajout de produits/services predefinis + if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) + { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + $var=! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + } + + print '
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('TotalHTShort').''.$langs->trans('TotalTTCShort').'  
'; + if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $object->lines[$i]->fk_product) + { + print ''; + $product_static=new ProductFournisseur($db); + $product_static->fetch($object->lines[$i]->fk_product); + $text=$product_static->getNomUrl(1); + $text.= ' - '.$product_static->libelle; + print $text; + print '
'; + } + else + { + $forceall=1; // For suppliers, we always show all types + print $form->select_type_of_lines($object->lines[$i]->product_type,'type',1); + if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) + || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '
'; + } + + if (is_object($hookmanager)) + { + $parameters=array('fk_parent_line'=>$line->fk_parent_line, 'line'=>$object->lines[$i],'var'=>$var,'num'=>$num,'i'=>$i); + $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$object,$action); + } + + // Description - Editor wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $nbrows=ROWS_2; + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $doleditor=new DolEditor('desc',$object->lines[$i]->description,'',128,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor->Create(); + print '
'; + print $form->load_tva('tauxtva',$object->lines[$i]->tva_tx,$societe,$mysoc); + print '%  '; + print '
'; + if ($object->lines[$i]->fk_product) + { + print ''; // ancre pour retourner sur la ligne + + $product_static=new ProductFournisseur($db); + $product_static->fetch($object->lines[$i]->fk_product); + $text=$product_static->getNomUrl(1); + $text.= ' - '.$product_static->libelle; + $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($object->lines[$i]->description)); + print $form->textwithtooltip($text,$description,3,'','',$i); + + // Show range + print_date_range($date_start,$date_end); + + // Add description in form + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print ($object->lines[$i]->description && $object->lines[$i]->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($object->lines[$i]->description):''; + } + + // Description - Editor wysiwyg + if (! $object->lines[$i]->fk_product) + { + if ($type==1) $text = img_object($langs->trans('Service'),'service'); + else $text = img_object($langs->trans('Product'),'product'); + print $text.' '.nl2br($object->lines[$i]->description); + + // Show range + print_date_range($date_start,$date_end); + } + print '
'.vatrate($object->lines[$i]->tva_tx).'%'.price($object->lines[$i]->pu_ht,'MU').''.($object->lines[$i]->pu_ttc?price($object->lines[$i]->pu_ttc,'MU'):' ').''.$object->lines[$i]->qty.''.(($object->lines[$i]->remise_percent > 0)?$object->lines[$i]->remise_percent.'%':'').''.price($object->lines[$i]->total_ht).''.price($object->lines[$i]->total_ttc).''; + if ($object->statut == 0) print 'lines[$i]->rowid.'">'.img_edit().''; + else print ' '; + print ''; + if ($object->statut == 0) print 'lines[$i]->rowid.'">'.img_delete().''; + else print ' '; + print '
'; + print ''; // ancre + print $langs->trans('AddNewLine').' - '.$langs->trans("FreeZone").''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('PriceUTTC').''.$langs->trans('Qty').'     
'; + + $forceall=1; // For suppliers, we always show all types + print $form->select_type_of_lines(isset($_POST["type"])?$_POST["type"]:-1,'type',1,0,$forceall); + if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) + || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '
'; + + if (is_object($hookmanager)) + { + $parameters=array(); + $reshook=$hookmanager->executeHooks('formCreateProductOptions',$parameters,$object,$action); + } + + // Editor wysiwyg + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $nbrows=ROWS_2; + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $doleditor=new DolEditor('dp_desc',GETPOST("dp_desc"),'',100,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); + $doleditor->Create(); + + print '
'; + print $form->load_tva('tauxtva',(GETPOST('tauxtva')?GETPOST('tauxtva'):-1),$societe,$mysoc); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '%  
'; + print $langs->trans("AddNewLine").' - '; + if (! empty($conf->service->enabled)) + { + print $langs->trans('RecordedProductsAndServices'); + } + else + { + print $langs->trans('RecordedProducts'); + } + print ''.$langs->trans('Qty').'   
'; + + $ajaxoptions=array( + 'update' => array('pqty' => 'qty', 'p_remise_percent' => 'discount'), + 'disabled' => 'addPredefinedProductButton', + 'error' => $langs->trans("NoPriceDefinedForThisSupplier") + ); + $form->select_produits_fournisseurs($object->socid, '', 'idprodfournprice', '', '', $ajaxoptions); + + if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) print '
'; + + if (is_object($hookmanager)) + { + $parameters=array('htmlname'=>'idprodfournprice'); + $reshook=$hookmanager->executeHooks('formCreateProductSupplierOptions',$parameters,$object,$action); + } + + $nbrows=ROWS_2; + if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; + $doleditor = new DolEditor('np_desc', GETPOST('np_desc'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, $nbrows, 70); + $doleditor->Create(); + + print '
%  
'; + + print ''; + + if ($action != 'presend') + { + + /* + * Boutons actions + */ + + print '
'; + + // Reopen a standard paid invoice + if (($object->type == 0 || $object->type == 1) && ($object->statut == 2 || $object->statut == 3)) // A paid invoice (partially or completely) + { + if (! $facidnext && $object->close_code != 'replaced') // Not replaced by another invoice + { + print ''.$langs->trans('ReOpen').''; + } + else + { + print ''.$langs->trans('ReOpen').''; + } + } + + // Send by mail + if (($object->statut == 1 || $object->statut == 2)) + { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->fournisseur->supplier_invoice_advance->send) + { + print ''.$langs->trans('SendByMail').''; + } + else print ''.$langs->trans('SendByMail').''; + } + + + //Make payments + if ($action != 'edit' && $object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + { + print ''.$langs->trans('DoPayment').''; + } + + //Classify paid + if ($action != 'edit' && $object->statut == 1 && $object->paye == 0 && $user->societe_id == 0) + { + print ''.$langs->trans('ClassifyPaid').''; + + //print ''.$langs->trans('ClassifyPaid').''; + } + + //Validate + if ($action != 'edit' && $object->statut == 0) + { + if (count($object->lines)) + { + if ($user->rights->fournisseur->facture->valider) + { + print ''.$langs->trans('Validate').''; + } + else + { + print ''.$langs->trans('Validate').''; + } + } + } + + //Clone + if ($action != 'edit' && $user->rights->fournisseur->facture->creer) + { + print 'socid.'">'.$langs->trans('ToClone').''; + } + + //Delete + if ($action != 'edit' && $user->rights->fournisseur->facture->supprimer) + { + print ''.$langs->trans('Delete').''; + } + print '
'; + + if ($action != 'edit') + { + print '
'; + print ''; // ancre + + /* + * Documents generes + */ + + $ref=dol_sanitizeFileName($object->ref); + $subdir = get_exdir($object->id,2).$ref; + $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$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:''); + + print '
'; + print $formfile->showdocuments('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,0,0,'','','',$societe->default_lang); + $somethingshown=$formfile->numoffiles; + + /* + * Linked object block + */ + $somethingshown=$object->showLinkedObjectBlock(); + + print '
'; + print '
'; + + // List of actions on element + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; + $formactions=new FormActions($db); + $somethingshown=$formactions->showactions($object,'invoice_supplier',$socid); + + print '
'; + } + } + /* + * Show mail form + */ + if ($action == 'presend') + { + $ref = dol_sanitizeFileName($object->ref); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref); + $file=$fileparams['fullname']; + + // Build document if it not exists + if (! $file || ! is_readable($file)) + { + // Define output language + $outputlangs = $langs; + $newlang=''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id']; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + $result=supplier_invoice_pdf_create($db, $object, GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + if ($result <= 0) + { + dol_print_error($db,$result); + exit; + } + $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref); + $file=$fileparams['fullname']; + } + + print '
'; + print_titre($langs->trans('SendBillByMail')); + + // Cree l'objet formulaire mail + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; + $formmail = new FormMail($db); + $formmail->fromtype = 'user'; + $formmail->fromid = $user->id; + $formmail->fromname = $user->getFullName($langs); + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; + $formmail->withtosocid=$soc->id; + $formmail->withtocc=1; + $formmail->withtoccsocid=0; + $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; + $formmail->withtocccsocid=0; + $formmail->withtopic=$langs->trans('SendBillRef','__FACREF__'); + $formmail->withfile=2; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + $formmail->substit['__FACREF__']=$object->ref; + $formmail->substit['__SIGNATURE__']=$user->signature; + $formmail->substit['__PERSONALIZED__']=''; + // Tableau des parametres complementaires + $formmail->param['action']='send'; + $formmail->param['models']='invoice_supplier_send'; + $formmail->param['facid']=$object->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; + + // Init list of files + if (GETPOST("mode")=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); + } + + // Show form + $formmail->show_form(); + + print '
'; + } + } +} + + +// End of page +llxFooter(); +$db->close(); +?>