diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 0515c8187c1..09aedd05e66 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -197,9 +197,9 @@ if ($_POST['action'] == 'update' && ! $_POST['cancel']) */ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) { - $error=0; + $error=0; - $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']); + $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 == '') @@ -232,93 +232,93 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) $facfou->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]; - }*/ + 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'; } + // 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'; } - $facfou->origin = $_POST['origin']; - $facfou->origin_id = $_POST['originid']; + $facfou->origin = $_POST['origin']; + $facfou->origin_id = $_POST['originid']; - $facid = $facfou->create($user); + $facid = $facfou->create($user); - // Add lines - if ($facid > 0) - { - require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php'); - $classname = ucfirst($subelement); - if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur'; - $srcobject = new $classname($db); + // Add lines + if ($facid > 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(); + $result=$srcobject->fetch($_POST['originid']); + if ($result > 0) + { + $lines = $srcobject->lines; + if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines(); - for ($i = 0 ; $i < sizeof($lines) ; $i++) - { - $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); - $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); + for ($i = 0 ; $i < sizeof($lines) ; $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; + // 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 = $facfou->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, + $result = $facfou->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 - ); + $product_type + ); - if ($result < 0) - { - $error++; - break; - } - } - } - else - { - $error++; - } - } - else - { - $error++; - } - } - // If some invoice's lines already known - else - { - $facid = $facfou->create($user); + if ($result < 0) + { + $error++; + break; + } + } + } + else + { + $error++; + } + } + else + { + $error++; + } + } + // If some invoice's lines already known + else + { + $facid = $facfou->create($user); if ($facid < 0) { $error++; @@ -326,7 +326,7 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) if (! $error) { - for ($i = 1 ; $i < 9 ; $i++) + for ($i = 1 ; $i < 9 ; $i++) { $label = $_POST['label'.$i]; $amountht = price2num($_POST['amount'.$i]); @@ -346,14 +346,14 @@ if ($_POST['action'] == 'add' && $user->rights->fournisseur->facture->creer) } $atleastoneline=1; - $product=new Product($db); - $product->fetch($_POST['idprod'.$i]); + $product=new Product($db); + $product->fetch($_POST['idprod'.$i]); - $ret=$facfou->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base); - if ($ret < 0) $error++; - } + $ret=$facfou->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base); + if ($ret < 0) $error++; + } } - } + } } if ($error) @@ -383,7 +383,7 @@ if ($_GET['action'] == 'del_ligne') // Modification d'une ligne if ($_REQUEST['action'] == 'update_line') { - if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification + if ($_REQUEST['etat'] == '1' && ! $_REQUEST['cancel']) // si on valide la modification { $facfou = new FactureFournisseur($db); $facfou->fetch($_GET['facid']); @@ -412,15 +412,15 @@ if ($_REQUEST['action'] == 'update_line') } else { - if ($facfou->socid) - { - $societe=new Societe($db); - $societe->fetch($facfou->socid); - } + if ($facfou->socid) + { + $societe=new Societe($db); + $societe->fetch($facfou->socid); + } $label = $_POST['label']; $type = $_POST["type"]?$_POST["type"]:0; $localtax1tx= get_localtax($_POST['tauxtva'], 1, $societe); - $localtax2tx= get_localtax($_POST['tauxtva'], 2, $societe); + $localtax2tx= get_localtax($_POST['tauxtva'], 2, $societe); } $result=$facfou->updateline($_GET['lineid'], $label, $pu, $_POST['tauxtva'], $localtax1tx, $localtax2tx, $_POST['qty'], $_POST['idprod'], $price_base_type, 0, $type); @@ -441,11 +441,11 @@ if ($_GET['action'] == 'addline') exit; } - if ($facfou->socid) - { - $societe=new Societe($db); - $societe->fetch($facfou->socid); - } + if ($facfou->socid) + { + $societe=new Societe($db); + $societe->fetch($facfou->socid); + } if ($_POST['idprodfournprice']) // > 0 or -1 { @@ -464,7 +464,7 @@ if ($_GET['action'] == 'addline') $tvatx=get_default_tva($societe,$mysoc,$product->id); $localtax1tx= get_localtax($tvatx, 1, $societe); - $localtax2tx= get_localtax($tvatx, 2, $societe); + $localtax2tx= get_localtax($tvatx, 2, $societe); $type = $product->type; @@ -480,8 +480,8 @@ if ($_GET['action'] == 'addline') else { $tauxtva = price2num($_POST['tauxtva']); - $localtax1tx= get_localtax($tauxtva, 1, $societe); - $localtax2tx= get_localtax($tauxtva, 2, $societe); + $localtax1tx= get_localtax($tauxtva, 1, $societe); + $localtax2tx= get_localtax($tauxtva, 2, $societe); if (! $_POST['label']) { @@ -528,8 +528,8 @@ if ($_GET['action'] == 'addline') unset($_POST['pu']); unset($_POST['tva_tx']); unset($_POST['label']); - unset($localtax1_tx); - unset($localtax2_tx); + unset($localtax1_tx); + unset($localtax2_tx); } else if (empty($mesg)) { @@ -621,7 +621,7 @@ if ($_GET['action'] == 'reopen' && $user->rights->fournisseur->facture->creer) /* * Add file in email form - */ +*/ if ($_POST['addfile']) { require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); @@ -638,7 +638,7 @@ if ($_POST['addfile']) /* * Remove file in email form - */ +*/ if (! empty($_POST['removedfile'])) { require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); @@ -655,7 +655,7 @@ if (! empty($_POST['removedfile'])) /* * Send mail - */ +*/ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel']) { $langs->load('mails'); @@ -747,7 +747,7 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] $facturefourn->actionmsg = $actionmsg; $facturefourn->actionmsg2 = $actionmsg2; $facturefourn->fk_element = $facturefourn->id; - $facturefourn->elementtype = $facturefourn->element; + $facturefourn->elementtype = $facturefourn->element; // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); @@ -812,14 +812,14 @@ if ($_POST['action'] == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] /* * Build document - */ +*/ if ($_REQUEST['action'] == 'builddoc') { /* * Generation de la facture - * definit dans /includes/modules/supplier_invoice/modules_facturefournisseur.php - */ + * definit dans /includes/modules/supplier_invoice/modules_facturefournisseur.php + */ // Save modele used $facture=new FactureFournisseur($db); @@ -866,7 +866,7 @@ if ($action=='remove_file') /* * View - */ +*/ llxHeader('','',''); @@ -887,53 +887,53 @@ if ($_GET['action'] == 'create') $societe->fetch($_GET['socid']); } - if (GETPOST('origin') && GETPOST('originid')) - { - // Parse element/subelement (ex: project_task) - $element = $subelement = GETPOST('origin'); + if (GETPOST('origin') && GETPOST('originid')) + { + // Parse element/subelement (ex: project_task) + $element = $subelement = GETPOST('origin'); - if ($element == 'project') - { + if ($element == 'project') + { $projectid=GETPOST('originid'); - } - else if (in_array($element,array('order_supplier'))) - { - // For compatibility - if ($element == 'order') { $element = $subelement = 'commande'; } + } + else if (in_array($element,array('order_supplier'))) + { + // 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'; } + + 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(); - 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:''); - $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; - $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); - } + $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 '
\n"; + print "\n"; + + // Show origin lines + if (is_object($objectsrc)) + { + print '| '; |