diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index adb368af4c2..5d2da968f27 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1559,13 +1559,17 @@ if ($id > 0 || ! empty($ref)) } // Send - if ($object->statut == 1 && $user->rights->propale->envoyer) + if ($object->statut == 1) { $propref = dol_sanitizeFileName($object->ref); $file = $conf->propale->dir_output . '/'.$propref.'/'.$propref.'.pdf'; if (file_exists($file)) { - print 'id.'&action=presend&mode=init">'.$langs->trans('SendByMail').''; + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propale->propal_advance->send) + { + print 'id.'&action=presend&mode=init">'.$langs->trans('SendByMail').''; + } + else print ''.$langs->trans('SendByMail').''; } } diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index b4e98cdcc30..c28a27c382f 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1173,7 +1173,7 @@ if ($action == 'create' && $user->rights->commande->creer) $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; - + // Object source contacts list $srccontactslist = $objectsrc->liste_contact(-1,'external',1); } @@ -1447,7 +1447,7 @@ else $head = commande_prepare_head($object); dol_fiche_head($head, 'order', $langs->trans("CustomerOrder"), 0, 'order'); - + $formconfirm=''; /* @@ -1522,7 +1522,7 @@ else // Paiement incomplet. On demande si motif = escompte ou autre $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneOrder'),$langs->trans('ConfirmCloneOrder',$object->ref),'confirm_clone',$formquestion,'yes',1); } - + // Hook of thirdparty module if (empty($formconfirm) && ! empty($object->hooks)) { @@ -1531,7 +1531,7 @@ else if (empty($formconfirm)) $formconfirm = $module->formconfirm($action,$object,$lineid); } } - + // Print form confirm print $formconfirm; @@ -1741,7 +1741,7 @@ else $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); } print ''; - + // Availability print '
| ';
@@ -1845,7 +1845,7 @@ else
* Lines
*/
$result = $object->getLinesArray();
-
+
$numlines = count($object->lines);
if ($conf->use_javascript_ajax && $object->statut == 0)
@@ -1915,14 +1915,15 @@ else
// Send
if ($object->statut > 0)
{
- if ($user->rights->commande->envoyer)
+ $comref = dol_sanitizeFileName($object->ref);
+ $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
+ if (file_exists($file))
{
- $comref = dol_sanitizeFileName($object->ref);
- $file = $conf->commande->dir_output . '/'.$comref.'/'.$comref.'.pdf';
- if (file_exists($file))
+ if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send))
{
print 'id.'&action=presend&mode=init">'.$langs->trans('SendByMail').'';
}
+ else print ''.$langs->trans('SendByMail').'';
}
}
@@ -1931,7 +1932,7 @@ else
if ($conf->expedition->enabled)
{
$numshipping = $object->nb_expedition();
-
+
if ($object->statut > 0 && $object->statut < 3 && $object->getNbOfProductsLines() > 0)
{
if ($user->rights->expedition->creer)
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 12a3739b88e..c2106eab306 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -75,7 +75,7 @@ $object=new Facture($db);
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
- $object->callHooks('objectcard');
+ $object->callHooks('objectcard');
}
@@ -87,72 +87,72 @@ if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
// Hook of thirdparty module
if (! empty($object->hooks))
{
- foreach($object->hooks as $module)
- {
- $module->doActions($object);
- $mesg = $module->error;
- }
+ foreach($object->hooks as $module)
+ {
+ $module->doActions($object);
+ $mesg = $module->error;
+ }
}
// 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'].'?facid='.$result);
- exit;
- }
- else
- {
- $mesg=$object->error;
- $action='';
- }
- }
+ 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'].'?facid='.$result);
+ exit;
+ }
+ else
+ {
+ $mesg=$object->error;
+ $action='';
+ }
+ }
}
if ($action == 'reopen' && $user->rights->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"].'?facid='.$id);
- exit;
- }
- else
- {
- $mesg=''.$object->error.' ';
- }
- }
+ $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"].'?facid='.$id);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$object->error.' ';
+ }
+ }
}
// Suppression de la facture
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->supprimer)
{
- if ($user->rights->facture->supprimer)
- {
- $result = $object->fetch($id);
- $result = $object->delete();
- if ($result > 0)
- {
- Header('Location: '.$_SERVER["PHP_SELF"]);
- exit;
- }
- else
- {
- $mesg=''.$object->error.' ';
- }
- }
+ if ($user->rights->facture->supprimer)
+ {
+ $result = $object->fetch($id);
+ $result = $object->delete();
+ if ($result > 0)
+ {
+ Header('Location: '.$_SERVER["PHP_SELF"]);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$object->error.' ';
+ }
+ }
}
/*
@@ -160,96 +160,96 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->
*/
if ($action == 'confirm_deleteline' && $confirm == 'yes')
{
- if ($user->rights->facture->creer)
- {
- $object->fetch($id);
- $object->fetch_thirdparty();
+ if ($user->rights->facture->creer)
+ {
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- $result = $object->deleteline($_GET['lineid'], $user);
- if ($result > 0)
- {
- // 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=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- if ($result > 0)
- {
- Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
- }
- }
- else
- {
- $mesg=''.$object->error.' ';
- $action='';
- }
- }
+ $result = $object->deleteline($_GET['lineid'], $user);
+ if ($result > 0)
+ {
+ // 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=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ if ($result > 0)
+ {
+ Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
+ exit;
+ }
+ }
+ else
+ {
+ $mesg=''.$object->error.' ';
+ $action='';
+ }
+ }
}
// Supprime affectation d'un avoir a la facture
if ($action == 'unlinkdiscount')
{
- if ($user->rights->facture->creer)
- {
- $discount=new DiscountAbsolute($db);
- $result=$discount->fetch($_GET["discountid"]);
- $discount->unlink_invoice();
- }
+ if ($user->rights->facture->creer)
+ {
+ $discount=new DiscountAbsolute($db);
+ $result=$discount->fetch($_GET["discountid"]);
+ $discount->unlink_invoice();
+ }
}
// Validation
if ($action == 'valid')
{
- $object->fetch($id);
+ $object->fetch($id);
- // On verifie signe facture
- if ($object->type == 2)
- {
- // Si avoir, le signe doit etre negatif
- if ($object->total_ht >= 0)
- {
- $mesg=''.$langs->trans("ErrorInvoiceAvoirMustBeNegative").' ';
- $action='';
- }
- }
- else
- {
- // Si non avoir, le signe doit etre positif
- if ($object->total_ht < 0)
- {
- $mesg=''.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").' ';
- $action='';
- }
- }
+ // On verifie signe facture
+ if ($object->type == 2)
+ {
+ // Si avoir, le signe doit etre negatif
+ if ($object->total_ht >= 0)
+ {
+ $mesg=''.$langs->trans("ErrorInvoiceAvoirMustBeNegative").' ';
+ $action='';
+ }
+ }
+ else
+ {
+ // Si non avoir, le signe doit etre positif
+ if ($object->total_ht < 0)
+ {
+ $mesg=''.$langs->trans("ErrorInvoiceOfThisTypeMustBePositive").' ';
+ $action='';
+ }
+ }
}
if ($action == 'classin')
{
- $object->fetch($id);
- $object->setProject($_POST['projectid']);
+ $object->fetch($id);
+ $object->setProject($_POST['projectid']);
}
if ($action == 'setmode')
{
- $object->fetch($id);
- $result=$object->mode_reglement($_POST['mode_reglement_id']);
- if ($result < 0) dol_print_error($object->db,$object->error);
+ $object->fetch($id);
+ $result=$object->mode_reglement($_POST['mode_reglement_id']);
+ if ($result < 0) dol_print_error($object->db,$object->error);
}
if ($action == 'setinvoicedate')
{
- $object->fetch($id);
- $object->date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']);
- if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date;
- $result=$object->update($user);
- if ($result < 0) dol_print_error($object->db,$object->error);
+ $object->fetch($id);
+ $object->date=dol_mktime(12,0,0,$_POST['invoicedatemonth'],$_POST['invoicedateday'],$_POST['invoicedateyear']);
+ if ($object->date_lim_reglement < $object->date) $object->date_lim_reglement=$object->date;
+ $result=$object->update($user);
+ if ($result < 0) dol_print_error($object->db,$object->error);
}
if ($action == 'setpaymentterm')
@@ -262,243 +262,243 @@ if ($action == 'setpaymentterm')
if ($action == 'setconditions')
{
- $object->fetch($id);
- $result=$object->cond_reglement($_POST['cond_reglement_id']);
- if ($result < 0) dol_print_error($object->db,$object->error);
+ $object->fetch($id);
+ $result=$object->cond_reglement($_POST['cond_reglement_id']);
+ if ($result < 0) dol_print_error($object->db,$object->error);
}
if ($action == 'setremisepercent' && $user->rights->facture->creer)
{
- $object->fetch($id);
- $result = $object->set_remise($user, $_POST['remise_percent']);
+ $object->fetch($id);
+ $result = $object->set_remise($user, $_POST['remise_percent']);
}
if ($action == "setabsolutediscount" && $user->rights->facture->creer)
{
- // POST[remise_id] ou POST[remise_id_for_payment]
- if (! empty($_POST["remise_id"]))
- {
- $ret=$object->fetch($id);
- if ($ret > 0)
- {
- $result=$object->insert_discount($_POST["remise_id"]);
- if ($result < 0)
- {
- $mesg=''.$object->error.' ';
- }
- }
- else
- {
- dol_print_error($db,$object->error);
- }
- }
- if (! empty($_POST["remise_id_for_payment"]))
- {
- require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
- $discount = new DiscountAbsolute($db);
- $discount->fetch($_POST["remise_id_for_payment"]);
+ // POST[remise_id] ou POST[remise_id_for_payment]
+ if (! empty($_POST["remise_id"]))
+ {
+ $ret=$object->fetch($id);
+ if ($ret > 0)
+ {
+ $result=$object->insert_discount($_POST["remise_id"]);
+ if ($result < 0)
+ {
+ $mesg=''.$object->error.' ';
+ }
+ }
+ else
+ {
+ dol_print_error($db,$object->error);
+ }
+ }
+ if (! empty($_POST["remise_id_for_payment"]))
+ {
+ require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
+ $discount = new DiscountAbsolute($db);
+ $discount->fetch($_POST["remise_id_for_payment"]);
- $result=$discount->link_to_invoice(0,$id);
- if ($result < 0)
- {
- $mesg=''.$discount->error.' ';
- }
- }
+ $result=$discount->link_to_invoice(0,$id);
+ if ($result < 0)
+ {
+ $mesg=''.$discount->error.' ';
+ }
+ }
}
if ($action == 'set_ref_client')
{
- $object->fetch($id);
- $object->set_ref_client($_POST['ref_client']);
+ $object->fetch($id);
+ $object->set_ref_client($_POST['ref_client']);
}
// Classify to validated
if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->valider)
{
- $object->fetch($id);
- $object->fetch_thirdparty();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- $result = $object->validate($user);
- if ($result >= 0)
- {
- // 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);
- }
- facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- }
- else
- {
- $mesg=''.$object->error.' ';
- }
+ $result = $object->validate($user);
+ if ($result >= 0)
+ {
+ // 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);
+ }
+ facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ }
+ else
+ {
+ $mesg=''.$object->error.' ';
+ }
}
// Repasse la facture en mode brouillon (unvalidate)
if ($action == 'modif' && $user->rights->facture->unvalidate)
{
- $object->fetch($id);
- $object->fetch_thirdparty();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- // On verifie si la facture a des paiements
- $sql = 'SELECT pf.amount';
- $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
- $sql.= ' WHERE pf.fk_facture = '.$object->id;
+ // On verifie si la facture a des paiements
+ $sql = 'SELECT pf.amount';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
+ $sql.= ' WHERE pf.fk_facture = '.$object->id;
- $result = $db->query($sql);
- if ($result)
- {
- $i = 0;
- $num = $db->num_rows($result);
+ $result = $db->query($sql);
+ if ($result)
+ {
+ $i = 0;
+ $num = $db->num_rows($result);
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- $totalpaye += $objp->amount;
- $i++;
- }
- }
- else
- {
- dol_print_error($db,'');
- }
+ while ($i < $num)
+ {
+ $objp = $db->fetch_object($result);
+ $totalpaye += $objp->amount;
+ $i++;
+ }
+ }
+ else
+ {
+ dol_print_error($db,'');
+ }
- $resteapayer = $object->total_ttc - $totalpaye;
+ $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 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);
+ // On verifie si aucun paiement n'a ete effectue
+ if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
+ {
+ $object->set_draft($user);
- // 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);
- }
- facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- }
+ // 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);
+ }
+ facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ }
}
// Classify "paid"
if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->facture->paiement)
{
- $object->fetch($id);
- $result = $object->set_paid($user);
+ $object->fetch($id);
+ $result = $object->set_paid($user);
}
// Classif "paid partialy"
if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->rights->facture->paiement)
{
- $object->fetch($id);
- $close_code=$_POST["close_code"];
- $close_note=$_POST["close_note"];
- if ($close_code)
- {
- $result = $object->set_paid($user,$close_code,$close_note);
- }
- else
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).' ';
- }
+ $object->fetch($id);
+ $close_code=$_POST["close_code"];
+ $close_note=$_POST["close_note"];
+ if ($close_code)
+ {
+ $result = $object->set_paid($user,$close_code,$close_note);
+ }
+ else
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).' ';
+ }
}
// Classify "abandoned"
if ($action == 'confirm_canceled' && $confirm == 'yes')
{
- $object->fetch($id);
- $close_code=$_POST["close_code"];
- $close_note=$_POST["close_note"];
- if ($close_code)
- {
- $result = $object->set_canceled($user,$close_code,$close_note);
- }
- else
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).' ';
- }
+ $object->fetch($id);
+ $close_code=$_POST["close_code"];
+ $close_note=$_POST["close_note"];
+ if ($close_code)
+ {
+ $result = $object->set_canceled($user,$close_code,$close_note);
+ }
+ else
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).' ';
+ }
}
// Convertir en reduc
if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer)
{
- $db->begin();
+ $db->begin();
- $object->fetch($id);
- $object->fetch_thirdparty();
- $object->fetch_lines();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->fetch_lines();
- if (! $object->paye) // protection against multiple submit
- {
- // Boucle sur chaque taux de tva
- $i=0;
- foreach($object->lines as $line)
- {
- $amount_ht[$line->tva_tx]+=$line->total_ht;
- $amount_tva[$line->tva_tx]+=$line->total_tva;
- $amount_ttc[$line->tva_tx]+=$line->total_ttc;
- $i++;
- }
+ if (! $object->paye) // protection against multiple submit
+ {
+ // Boucle sur chaque taux de tva
+ $i=0;
+ foreach($object->lines as $line)
+ {
+ $amount_ht[$line->tva_tx]+=$line->total_ht;
+ $amount_tva[$line->tva_tx]+=$line->total_tva;
+ $amount_ttc[$line->tva_tx]+=$line->total_ttc;
+ $i++;
+ }
- // Insert one discount by VAT rate category
- $discount = new DiscountAbsolute($db);
- if ($object->type == 2) $discount->description='(CREDIT_NOTE)';
- elseif ($object->type == 3) $discount->description='(DEPOSIT)';
- else {
- $this->error="CantConvertToReducAnInvoiceOfThisType";
- return -1;
- }
- $discount->tva_tx=abs($object->total_ttc);
- $discount->fk_soc=$object->socid;
- $discount->fk_facture_source=$object->id;
+ // Insert one discount by VAT rate category
+ $discount = new DiscountAbsolute($db);
+ if ($object->type == 2) $discount->description='(CREDIT_NOTE)';
+ elseif ($object->type == 3) $discount->description='(DEPOSIT)';
+ else {
+ $this->error="CantConvertToReducAnInvoiceOfThisType";
+ return -1;
+ }
+ $discount->tva_tx=abs($object->total_ttc);
+ $discount->fk_soc=$object->socid;
+ $discount->fk_facture_source=$object->id;
- $error=0;
- foreach($amount_ht as $tva_tx => $xxx)
- {
- $discount->amount_ht=abs($amount_ht[$tva_tx]);
- $discount->amount_tva=abs($amount_tva[$tva_tx]);
- $discount->amount_ttc=abs($amount_ttc[$tva_tx]);
- $discount->tva_tx=abs($tva_tx);
+ $error=0;
+ foreach($amount_ht as $tva_tx => $xxx)
+ {
+ $discount->amount_ht=abs($amount_ht[$tva_tx]);
+ $discount->amount_tva=abs($amount_tva[$tva_tx]);
+ $discount->amount_ttc=abs($amount_ttc[$tva_tx]);
+ $discount->tva_tx=abs($tva_tx);
- $result=$discount->create($user);
- if ($result < 0)
- {
- $error++;
- break;
- }
- }
+ $result=$discount->create($user);
+ if ($result < 0)
+ {
+ $error++;
+ break;
+ }
+ }
- if (! $error)
- {
- // Classe facture
- $result=$object->set_paid($user);
- if ($result > 0)
- {
- //$mesg='OK'.$discount->id;
- $db->commit();
- }
- else
- {
- $mesg=''.$object->error.' ';
- $db->rollback();
- }
- }
- else
- {
- $mesg=''.$discount->error.' ';
- $db->rollback();
- }
- }
+ if (! $error)
+ {
+ // Classe facture
+ $result=$object->set_paid($user);
+ if ($result > 0)
+ {
+ //$mesg='OK'.$discount->id;
+ $db->commit();
+ }
+ else
+ {
+ $mesg=''.$object->error.' ';
+ $db->rollback();
+ }
+ }
+ else
+ {
+ $mesg=''.$discount->error.' ';
+ $db->rollback();
+ }
+ }
}
@@ -508,405 +508,405 @@ if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->f
*/
if ($action == 'add' && $user->rights->facture->creer)
{
- $object->socid=GETPOST('socid');
+ $object->socid=GETPOST('socid');
- $db->begin();
+ $db->begin();
- // Replacement invoice
- if ($_POST['type'] == 1)
- {
- $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error=1;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
- }
+ // Replacement invoice
+ if ($_POST['type'] == 1)
+ {
+ $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (empty($datefacture))
+ {
+ $error=1;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
+ }
- if (! ($_POST['fac_replacement'] > 0))
- {
- $error=1;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).' ';
- }
+ if (! ($_POST['fac_replacement'] > 0))
+ {
+ $error=1;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("ReplaceInvoice")).' ';
+ }
- if (! $error)
- {
- // This is a replacement invoice
- $result=$object->fetch($_POST['fac_replacement']);
- $object->fetch_thirdparty();
+ if (! $error)
+ {
+ // This is a replacement invoice
+ $result=$object->fetch($_POST['fac_replacement']);
+ $object->fetch_thirdparty();
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note = trim($_POST['note']);
- $object->ref_client = $_POST['ref_client'];
- $object->modelpdf = $_POST['model'];
- $object->fk_project = $_POST['projectid'];
- $object->cond_reglement_id = $_POST['cond_reglement_id'];
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->remise_percent = $_POST['remise_percent'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST['note_public']);
+ $object->note = trim($_POST['note']);
+ $object->ref_client = $_POST['ref_client'];
+ $object->modelpdf = $_POST['model'];
+ $object->fk_project = $_POST['projectid'];
+ $object->cond_reglement_id = $_POST['cond_reglement_id'];
+ $object->mode_reglement_id = $_POST['mode_reglement_id'];
+ $object->remise_absolue = $_POST['remise_absolue'];
+ $object->remise_percent = $_POST['remise_percent'];
- // Proprietes particulieres a facture de remplacement
- $object->fk_facture_source = $_POST['fac_replacement'];
- $object->type = 1;
+ // Proprietes particulieres a facture de remplacement
+ $object->fk_facture_source = $_POST['fac_replacement'];
+ $object->type = 1;
- $id=$object->createFromCurrent($user);
- if ($id <= 0) $mesg=$object->error;
- }
- }
+ $id=$object->createFromCurrent($user);
+ if ($id <= 0) $mesg=$object->error;
+ }
+ }
- // Credit note invoice
- if ($_POST['type'] == 2)
- {
- if (! $_POST['fac_avoir'] > 0)
- {
- $error=1;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).' ';
- }
+ // Credit note invoice
+ if ($_POST['type'] == 2)
+ {
+ if (! $_POST['fac_avoir'] > 0)
+ {
+ $error=1;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("CorrectInvoice")).' ';
+ }
- $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error=1;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
- }
+ $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (empty($datefacture))
+ {
+ $error=1;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
+ }
- if (! $error)
- {
- // Si facture avoir
- $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (! $error)
+ {
+ // Si facture avoir
+ $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- //$result=$object->fetch($_POST['fac_avoir']);
+ //$result=$object->fetch($_POST['fac_avoir']);
- $object->socid = $_POST['socid'];
- $object->number = $_POST['facnumber'];
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note = trim($_POST['note']);
- $object->ref_client = $_POST['ref_client'];
- $object->modelpdf = $_POST['model'];
- $object->fk_project = $_POST['projectid'];
- $object->cond_reglement_id = 0;
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->remise_percent = $_POST['remise_percent'];
+ $object->socid = $_POST['socid'];
+ $object->number = $_POST['facnumber'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST['note_public']);
+ $object->note = trim($_POST['note']);
+ $object->ref_client = $_POST['ref_client'];
+ $object->modelpdf = $_POST['model'];
+ $object->fk_project = $_POST['projectid'];
+ $object->cond_reglement_id = 0;
+ $object->mode_reglement_id = $_POST['mode_reglement_id'];
+ $object->remise_absolue = $_POST['remise_absolue'];
+ $object->remise_percent = $_POST['remise_percent'];
- // Proprietes particulieres a facture avoir
- $object->fk_facture_source = $_POST['fac_avoir'];
- $object->type = 2;
+ // Proprietes particulieres a facture avoir
+ $object->fk_facture_source = $_POST['fac_avoir'];
+ $object->type = 2;
- $id = $object->create($user);
+ $id = $object->create($user);
- // Add predefined lines
- for ($i = 1; $i <= $NBLINES; $i++)
- {
- if ($_POST['idprod'.$i])
- {
- $product=new Product($db);
- $product->fetch($_POST['idprod'.$i]);
- $startday=dol_mktime(12, 0 , 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
- $endday=dol_mktime(12, 0 , 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
- $result=$object->addline($id,$product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
- }
- }
- }
- }
+ // Add predefined lines
+ for ($i = 1; $i <= $NBLINES; $i++)
+ {
+ if ($_POST['idprod'.$i])
+ {
+ $product=new Product($db);
+ $product->fetch($_POST['idprod'.$i]);
+ $startday=dol_mktime(12, 0 , 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
+ $endday=dol_mktime(12, 0 , 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
+ $result=$object->addline($id,$product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
+ }
+ }
+ }
+ }
- // Standard invoice or Deposit invoice created from a Predefined invoice
- if (($_POST['type'] == 0 || $_POST['type'] == 3) && $_POST['fac_rec'] > 0)
- {
- $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error=1;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
- }
+ // Standard invoice or Deposit invoice created from a Predefined invoice
+ if (($_POST['type'] == 0 || $_POST['type'] == 3) && $_POST['fac_rec'] > 0)
+ {
+ $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (empty($datefacture))
+ {
+ $error=1;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
+ }
- if (! $error)
- {
- $object->socid = $_POST['socid'];
- $object->type = $_POST['type'];
- $object->number = $_POST['facnumber'];
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note = trim($_POST['note']);
- $object->ref_client = $_POST['ref_client'];
- $object->modelpdf = $_POST['model'];
+ if (! $error)
+ {
+ $object->socid = $_POST['socid'];
+ $object->type = $_POST['type'];
+ $object->number = $_POST['facnumber'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST['note_public']);
+ $object->note = trim($_POST['note']);
+ $object->ref_client = $_POST['ref_client'];
+ $object->modelpdf = $_POST['model'];
- // Source facture
- $object->fac_rec = $_POST['fac_rec'];
+ // Source facture
+ $object->fac_rec = $_POST['fac_rec'];
- $id = $object->create($user);
- }
- }
+ $id = $object->create($user);
+ }
+ }
- // Standard or deposit or proforma invoice
- if (($_POST['type'] == 0 || $_POST['type'] == 3 || $_POST['type'] == 4) && $_POST['fac_rec'] <= 0)
- {
- $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
- if (empty($datefacture))
- {
- $error=1;
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
- }
+ // Standard or deposit or proforma invoice
+ if (($_POST['type'] == 0 || $_POST['type'] == 3 || $_POST['type'] == 4) && $_POST['fac_rec'] <= 0)
+ {
+ $datefacture = dol_mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
+ if (empty($datefacture))
+ {
+ $error=1;
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Date")).' ';
+ }
- if (! $error)
- {
- // Si facture standard
- $object->socid = $_POST['socid'];
- $object->type = $_POST['type'];
- $object->number = $_POST['facnumber'];
- $object->date = $datefacture;
- $object->note_public = trim($_POST['note_public']);
- $object->note = trim($_POST['note']);
- $object->ref_client = $_POST['ref_client'];
- $object->modelpdf = $_POST['model'];
- $object->fk_project = $_POST['projectid'];
- $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
- $object->mode_reglement_id = $_POST['mode_reglement_id'];
- $object->amount = $_POST['amount'];
- $object->remise_absolue = $_POST['remise_absolue'];
- $object->remise_percent = $_POST['remise_percent'];
+ if (! $error)
+ {
+ // Si facture standard
+ $object->socid = $_POST['socid'];
+ $object->type = $_POST['type'];
+ $object->number = $_POST['facnumber'];
+ $object->date = $datefacture;
+ $object->note_public = trim($_POST['note_public']);
+ $object->note = trim($_POST['note']);
+ $object->ref_client = $_POST['ref_client'];
+ $object->modelpdf = $_POST['model'];
+ $object->fk_project = $_POST['projectid'];
+ $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']);
+ $object->mode_reglement_id = $_POST['mode_reglement_id'];
+ $object->amount = $_POST['amount'];
+ $object->remise_absolue = $_POST['remise_absolue'];
+ $object->remise_percent = $_POST['remise_percent'];
- // If creation from another object of another module (Example: origin=propal, originid=1)
- 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 creation from another object of another module (Example: origin=propal, originid=1)
+ 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'; }
+ // For compatibility
+ if ($element == 'order') { $element = $subelement = 'commande'; }
+ if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
+ if ($element == 'contract') { $element = $subelement = 'contrat'; }
- $object->origin = $_POST['origin'];
- $object->origin_id = $_POST['originid'];
+ $object->origin = $_POST['origin'];
+ $object->origin_id = $_POST['originid'];
- $id = $object->create($user);
+ $id = $object->create($user);
- if ($id > 0)
- {
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
+ if ($id > 0)
+ {
+ dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
- $classname = ucfirst($subelement);
- $srcobject = new $classname($db);
+ $classname = ucfirst($subelement);
+ $srcobject = new $classname($db);
- dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
- $result=$srcobject->fetch($object->origin_id);
- if ($result > 0)
- {
- $lines = $srcobject->lines;
- if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
+ dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
+ $result=$srcobject->fetch($object->origin_id);
+ if ($result > 0)
+ {
+ $lines = $srcobject->lines;
+ if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
- $fk_parent_line=0;
- $num=sizeof($lines);
+ $fk_parent_line=0;
+ $num=sizeof($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);
+ 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;
+ // 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;
- // Reset fk_parent_line for no child products and special product
- if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
- $fk_parent_line = 0;
- }
+ // Reset fk_parent_line for no child products and special product
+ if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
+ $fk_parent_line = 0;
+ }
- $result = $object->addline(
- $id,
- $desc,
- $lines[$i]->subprice,
- $lines[$i]->qty,
- $lines[$i]->tva_tx,
- $lines[$i]->localtax1_tx,
- $lines[$i]->localtax2_tx,
- $lines[$i]->fk_product,
- $lines[$i]->remise_percent,
- $date_start,
- $date_end,
- 0,
- $lines[$i]->info_bits,
- $lines[$i]->fk_remise_except,
+ $result = $object->addline(
+ $id,
+ $desc,
+ $lines[$i]->subprice,
+ $lines[$i]->qty,
+ $lines[$i]->tva_tx,
+ $lines[$i]->localtax1_tx,
+ $lines[$i]->localtax2_tx,
+ $lines[$i]->fk_product,
+ $lines[$i]->remise_percent,
+ $date_start,
+ $date_end,
+ 0,
+ $lines[$i]->info_bits,
+ $lines[$i]->fk_remise_except,
'HT',
- 0,
- $product_type,
- $lines[$i]->rang,
- $lines[$i]->special_code,
- $object->origin,
- $lines[$i]->rowid,
- $fk_parent_line
- );
+ 0,
+ $product_type,
+ $lines[$i]->rang,
+ $lines[$i]->special_code,
+ $object->origin,
+ $lines[$i]->rowid,
+ $fk_parent_line
+ );
- if ($result < 0)
- {
- $error++;
- break;
- }
+ if ($result < 0)
+ {
+ $error++;
+ break;
+ }
- // Defined the new fk_parent_line
- if ($result > 0 && $lines[$i]->product_type == 9) {
- $fk_parent_line = $result;
- }
- }
+ // Defined the new fk_parent_line
+ if ($result > 0 && $lines[$i]->product_type == 9) {
+ $fk_parent_line = $result;
+ }
+ }
- // Hooks
- if (! empty($object->hooks))
- {
- foreach($object->hooks as $module)
- {
- $res = $module->createfrom($srcobject,$id,$object->element);
- if ($res < 0) $error++;
- }
- }
- }
- else
- {
- $mesg=$srcobject->error;
- $error++;
- }
- }
- else
- {
- $mesg=$object->error;
- $error++;
- }
- }
- // If some invoice's lines already known
- else
- {
- $id = $object->create($user);
+ // Hooks
+ if (! empty($object->hooks))
+ {
+ foreach($object->hooks as $module)
+ {
+ $res = $module->createfrom($srcobject,$id,$object->element);
+ if ($res < 0) $error++;
+ }
+ }
+ }
+ else
+ {
+ $mesg=$srcobject->error;
+ $error++;
+ }
+ }
+ else
+ {
+ $mesg=$object->error;
+ $error++;
+ }
+ }
+ // If some invoice's lines already known
+ else
+ {
+ $id = $object->create($user);
- for ($i = 1; $i <= $NBLINES; $i++)
- {
- if ($_POST['idprod'.$i])
- {
- $product=new Product($db);
- $product->fetch($_POST['idprod'.$i]);
- $startday=dol_mktime(12, 0 , 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
- $endday=dol_mktime(12, 0 , 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
- $result=$object->addline($id,$product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
- }
- }
- }
- }
- }
+ for ($i = 1; $i <= $NBLINES; $i++)
+ {
+ if ($_POST['idprod'.$i])
+ {
+ $product=new Product($db);
+ $product->fetch($_POST['idprod'.$i]);
+ $startday=dol_mktime(12, 0 , 0, $_POST['date_start'.$i.'month'], $_POST['date_start'.$i.'day'], $_POST['date_start'.$i.'year']);
+ $endday=dol_mktime(12, 0 , 0, $_POST['date_end'.$i.'month'], $_POST['date_end'.$i.'day'], $_POST['date_end'.$i.'year']);
+ $result=$object->addline($id,$product->description,$product->price, $_POST['qty'.$i], $product->tva_tx, $product->localtax1_tx, $product->localtax2_tx, $_POST['idprod'.$i], $_POST['remise_percent'.$i], $startday, $endday, 0, 0, '', $product->price_base_type, $product->price_ttc, $product->type);
+ }
+ }
+ }
+ }
+ }
- // End of object creation, we show it
- if ($id > 0 && ! $error)
- {
- $db->commit();
- Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
- exit;
- }
- else
- {
- $db->rollback();
- $_GET["action"]='create';
- $_GET["origin"]=$_POST["origin"];
- $_GET["originid"]=$_POST["originid"];
- if (! $mesg) $mesg=''.$object->error.' ';
- }
+ // End of object creation, we show it
+ if ($id > 0 && ! $error)
+ {
+ $db->commit();
+ Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ $_GET["action"]='create';
+ $_GET["origin"]=$_POST["origin"];
+ $_GET["originid"]=$_POST["originid"];
+ if (! $mesg) $mesg=''.$object->error.' ';
+ }
}
// Add a new line
if (($action == 'addline' || $action == 'addline_predef') && $user->rights->facture->creer)
{
- $result=0;
+ $result=0;
- if (empty($_POST['idprod']) && $_POST["type"] < 0)
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).' ';
- $result = -1 ;
- }
- if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]=='')) // Unit price can be 0 but not ''
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).' ';
- $result = -1 ;
- }
- if (empty($_POST['idprod']) && empty($_POST["np_desc"]) && empty($_POST["dp_desc"]))
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).' ';
- $result = -1 ;
- }
- if (! isset($_POST['qty']) || $_POST['qty']=='')
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Qty')).' ';
- $result = -1 ;
- }
- if ($result >= 0 && ( ($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'] ) )
- {
- $ret=$object->fetch($id);
- if ($ret < 0)
- {
- dol_print_error($db,$object->error);
- exit;
- }
- $ret=$object->fetch_thirdparty();
+ if (empty($_POST['idprod']) && $_POST["type"] < 0)
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).' ';
+ $result = -1 ;
+ }
+ if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]=='')) // Unit price can be 0 but not ''
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")).' ';
+ $result = -1 ;
+ }
+ if (empty($_POST['idprod']) && empty($_POST["np_desc"]) && empty($_POST["dp_desc"]))
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Description")).' ';
+ $result = -1 ;
+ }
+ if (! isset($_POST['qty']) || $_POST['qty']=='')
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv('Qty')).' ';
+ $result = -1 ;
+ }
+ if ($result >= 0 && ( ($_POST['np_price']!='' && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprod'] ) )
+ {
+ $ret=$object->fetch($id);
+ if ($ret < 0)
+ {
+ dol_print_error($db,$object->error);
+ exit;
+ }
+ $ret=$object->fetch_thirdparty();
- $suffixe = $_POST['idprod'] ? '_predef' : '';
- $date_start=dol_mktime($_POST['date_start'.$suffixe.'hour'],$_POST['date_start'.$suffixe.'min'],$_POST['date_start'.$suffixe.'sec'],$_POST['date_start'.$suffixe.'month'],$_POST['date_start'.$suffixe.'day'],$_POST['date_start'.$suffixe.'year']);
- $date_end=dol_mktime($_POST['date_end'.$suffixe.'hour'],$_POST['date_end'.$suffixe.'min'],$_POST['date_end'.$suffixe.'sec'],$_POST['date_end'.$suffixe.'month'],$_POST['date_end'.$suffixe.'day'],$_POST['date_end'.$suffixe.'year']);
+ $suffixe = $_POST['idprod'] ? '_predef' : '';
+ $date_start=dol_mktime($_POST['date_start'.$suffixe.'hour'],$_POST['date_start'.$suffixe.'min'],$_POST['date_start'.$suffixe.'sec'],$_POST['date_start'.$suffixe.'month'],$_POST['date_start'.$suffixe.'day'],$_POST['date_start'.$suffixe.'year']);
+ $date_end=dol_mktime($_POST['date_end'.$suffixe.'hour'],$_POST['date_end'.$suffixe.'min'],$_POST['date_end'.$suffixe.'sec'],$_POST['date_end'.$suffixe.'month'],$_POST['date_end'.$suffixe.'day'],$_POST['date_end'.$suffixe.'year']);
- $price_base_type = 'HT';
+ $price_base_type = 'HT';
- // Ecrase $pu par celui du produit
- // Ecrase $desc par celui du produit
- // Ecrase $txtva par celui du produit
- // Ecrase $base_price_type par celui du produit
- if ($_POST['idprod'])
- {
- $prod = new Product($db, $_POST['idprod']);
- $prod->fetch($_POST['idprod']);
+ // Ecrase $pu par celui du produit
+ // Ecrase $desc par celui du produit
+ // Ecrase $txtva par celui du produit
+ // Ecrase $base_price_type par celui du produit
+ if ($_POST['idprod'])
+ {
+ $prod = new Product($db, $_POST['idprod']);
+ $prod->fetch($_POST['idprod']);
- $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
- $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
+ $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
+ $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
- // We define price for product
- if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level)
- {
- $pu_ht = $prod->multiprices[$object->client->price_level];
- $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
- $price_min = $prod->multiprices_min[$object->client->price_level];
- $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
- }
- else
- {
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
- $price_min = $prod->price_min;
- $price_base_type = $prod->price_base_type;
- }
+ // We define price for product
+ if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level)
+ {
+ $pu_ht = $prod->multiprices[$object->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
+ $price_min = $prod->multiprices_min[$object->client->price_level];
+ $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
+ }
+ else
+ {
+ $pu_ht = $prod->price;
+ $pu_ttc = $prod->price_ttc;
+ $price_min = $prod->price_min;
+ $price_base_type = $prod->price_base_type;
+ }
- // On reevalue prix selon taux tva car taux tva transaction peut etre different
- // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- if ($tva_tx != $prod->tva_tx)
- {
- if ($price_base_type != 'HT')
- {
- $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
- }
- else
- {
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
- }
- }
+ // On reevalue prix selon taux tva car taux tva transaction peut etre different
+ // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
+ if ($tva_tx != $prod->tva_tx)
+ {
+ if ($price_base_type != 'HT')
+ {
+ $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
+ }
+ else
+ {
+ $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
+ }
+ }
- $desc = $prod->description;
+ $desc = $prod->description;
$desc.= ($prod->description && $_POST['np_desc']) ? ((dol_textishtml($prod->description) || dol_textishtml($_POST['np_desc']))?"\n":"\n") : ""; - $desc.= $_POST['np_desc']; + $desc.= $_POST['np_desc']; if (! empty($prod->customcode) || ! empty($prod->country_code)) { $tmptxt='('; @@ -916,174 +916,174 @@ if (($action == 'addline' || $action == 'addline_predef') && $user->rights->fact $tmptxt.=')'; $desc.= (dol_textishtml($desc)?" \n":"\n").$tmptxt; } - $type = $prod->type; - } - else - { - $pu_ht=$_POST['np_price']; - $tva_tx=str_replace('*','',$_POST['np_tva_tx']); - $tva_npr=preg_match('/\*/',$_POST['np_tva_tx'])?1:0; - $desc=$_POST['dp_desc']; - $type=$_POST["type"]; - } + $type = $prod->type; + } + else + { + $pu_ht=$_POST['np_price']; + $tva_tx=str_replace('*','',$_POST['np_tva_tx']); + $tva_npr=preg_match('/\*/',$_POST['np_tva_tx'])?1:0; + $desc=$_POST['dp_desc']; + $type=$_POST["type"]; + } - $localtax1_tx=get_localtax($tva_tx,1,$object->client); - $localtax2_tx=get_localtax($tva_tx,2,$object->client); + $localtax1_tx=get_localtax($tva_tx,1,$object->client); + $localtax2_tx=get_localtax($tva_tx,2,$object->client); - $info_bits=0; - if ($tva_npr) $info_bits |= 0x01; + $info_bits=0; + if ($tva_npr) $info_bits |= 0x01; - if ($result >= 0) - { - if($price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min))) - { - $object->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ; - $result = -1 ; - } - else - { - // Insert line - $result = $object->addline( - $id, - $desc, - $pu_ht, - $_POST['qty'], - $tva_tx, - $localtax1_tx, - $localtax2_tx, - $_POST['idprod'], - $_POST['remise_percent'], - $date_start, - $date_end, - 0, - $info_bits, + if ($result >= 0) + { + if($price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min))) + { + $object->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ; + $result = -1 ; + } + else + { + // Insert line + $result = $object->addline( + $id, + $desc, + $pu_ht, + $_POST['qty'], + $tva_tx, + $localtax1_tx, + $localtax2_tx, + $_POST['idprod'], + $_POST['remise_percent'], + $date_start, + $date_end, + 0, + $info_bits, '', - $price_base_type, - $pu_ttc, - $type - ); - } - } - } + $price_base_type, + $pu_ttc, + $type + ); + } + } + } - if ($result > 0) - { - // 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); - } - facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); + if ($result > 0) + { + // 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); + } + facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref')); - unset($_POST['qty']); - unset($_POST['type']); - unset($_POST['idprod']); - unset($_POST['remmise_percent']); - unset($_POST['dp_desc']); - unset($_POST['np_desc']); - unset($_POST['np_price']); - unset($_POST['np_tva_tx']); - } - else - { - if (empty($mesg)) $mesg=' '.$object->error.' ';
- }
+ unset($_POST['qty']);
+ unset($_POST['type']);
+ unset($_POST['idprod']);
+ unset($_POST['remmise_percent']);
+ unset($_POST['dp_desc']);
+ unset($_POST['np_desc']);
+ unset($_POST['np_price']);
+ unset($_POST['np_tva_tx']);
+ }
+ else
+ {
+ if (empty($mesg)) $mesg=''.$object->error.' ';
+ }
- $_POST["action"]='';
+ $_POST["action"]='';
}
if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['save'] == $langs->trans('Save'))
{
- if (! $object->fetch($id) > 0) dol_print_error($db);
- $object->fetch_thirdparty();
+ if (! $object->fetch($id) > 0) dol_print_error($db);
+ $object->fetch_thirdparty();
- // Clean parameters
- $date_start='';
- $date_end='';
- $date_start=dol_mktime($_POST['date_start'.$suffixe.'hour'],$_POST['date_start'.$suffixe.'min'],$_POST['date_start'.$suffixe.'sec'],$_POST['date_start'.$suffixe.'month'],$_POST['date_start'.$suffixe.'day'],$_POST['date_start'.$suffixe.'year']);
- $date_end=dol_mktime($_POST['date_end'.$suffixe.'hour'],$_POST['date_end'.$suffixe.'min'],$_POST['date_end'.$suffixe.'sec'],$_POST['date_end'.$suffixe.'month'],$_POST['date_end'.$suffixe.'day'],$_POST['date_end'.$suffixe.'year']);
- $description=dol_htmlcleanlastbr($_POST['desc']);
+ // Clean parameters
+ $date_start='';
+ $date_end='';
+ $date_start=dol_mktime($_POST['date_start'.$suffixe.'hour'],$_POST['date_start'.$suffixe.'min'],$_POST['date_start'.$suffixe.'sec'],$_POST['date_start'.$suffixe.'month'],$_POST['date_start'.$suffixe.'day'],$_POST['date_start'.$suffixe.'year']);
+ $date_end=dol_mktime($_POST['date_end'.$suffixe.'hour'],$_POST['date_end'.$suffixe.'min'],$_POST['date_end'.$suffixe.'sec'],$_POST['date_end'.$suffixe.'month'],$_POST['date_end'.$suffixe.'day'],$_POST['date_end'.$suffixe.'year']);
+ $description=dol_htmlcleanlastbr($_POST['desc']);
$up_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice');
- // Define info_bits
- $info_bits=0;
- if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01;
+ // Define info_bits
+ $info_bits=0;
+ if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01;
- // Define vat_rate
- $vat_rate=$_POST['tva_tx'];
- $vat_rate=str_replace('*','',$vat_rate);
- $localtax1_rate=get_localtax($vat_rate,1,$object->client);
- $localtax2_rate=get_localtax($vat_rate,2,$object->client);
+ // Define vat_rate
+ $vat_rate=$_POST['tva_tx'];
+ $vat_rate=str_replace('*','',$vat_rate);
+ $localtax1_rate=get_localtax($vat_rate,1,$object->client);
+ $localtax2_rate=get_localtax($vat_rate,2,$object->client);
- // Check parameters
- if (! GETPOST('productid') && GETPOST("type") < 0)
- {
- $mesg = ''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).' ';
- $result = -1 ;
- }
- // Check minimum price
- if (GETPOST('productid'))
- {
- $productid = GETPOST('productid');
- $product = new Product($db);
- $product->fetch($productid);
- $type=$product->type;
- $price_min = $product->price_min;
- if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level];
- }
- if ($object->type!=2 && $price_min && GETPOST('productid') && (price2num($up_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
- {
- //print "CantBeLessThanMinPrice ".$up_ht." - ".GETPOST('remise_percent')." - ".$product->price_min;
- $mesg = ''.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).' ';
- $result=-1;
- }
+ // Check parameters
+ if (! GETPOST('productid') && GETPOST("type") < 0)
+ {
+ $mesg = ''.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")).' ';
+ $result = -1 ;
+ }
+ // Check minimum price
+ if (GETPOST('productid'))
+ {
+ $productid = GETPOST('productid');
+ $product = new Product($db);
+ $product->fetch($productid);
+ $type=$product->type;
+ $price_min = $product->price_min;
+ if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level];
+ }
+ if ($object->type!=2 && $price_min && GETPOST('productid') && (price2num($up_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
+ {
+ //print "CantBeLessThanMinPrice ".$up_ht." - ".GETPOST('remise_percent')." - ".$product->price_min;
+ $mesg = ''.$langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)).' ';
+ $result=-1;
+ }
- // Define params
- if (GETPOST('productid')) $type=$product->type;
- else $type=GETPOST("type");
+ // Define params
+ if (GETPOST('productid')) $type=$product->type;
+ else $type=GETPOST("type");
- // Update line
- if ($result >= 0)
- {
- $result = $object->updateline(GETPOST('lineid'),
- $description,
- $up_ht,
- GETPOST('qty'),
- GETPOST('remise_percent'),
- $date_start,
- $date_end,
- $vat_rate,
- $localtax1_rate,
- $localtax2_rate,
+ // Update line
+ if ($result >= 0)
+ {
+ $result = $object->updateline(GETPOST('lineid'),
+ $description,
+ $up_ht,
+ GETPOST('qty'),
+ GETPOST('remise_percent'),
+ $date_start,
+ $date_end,
+ $vat_rate,
+ $localtax1_rate,
+ $localtax2_rate,
'HT',
- $info_bits,
- $type,
- GETPOST('fk_parent_line')
- );
+ $info_bits,
+ $type,
+ GETPOST('fk_parent_line')
+ );
- // Define output language
- $outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- }
+ // Define output language
+ $outputlangs = $langs;
+ $newlang='';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ }
}
if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['cancel'] == $langs->trans('Cancel'))
{
- Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); // Pour reaffichage de la fiche en cours d'edition
- exit;
+ Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$id); // Pour reaffichage de la fiche en cours d'edition
+ exit;
}
@@ -1093,46 +1093,46 @@ if ($action == 'updateligne' && $user->rights->facture->creer && $_POST['cancel'
if ($action == 'up' && $user->rights->facture->creer)
{
- $object->fetch($id);
- $object->fetch_thirdparty();
- $object->line_up($_GET['rowid']);
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->line_up($_GET['rowid']);
- // 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);
- }
- facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ // 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);
+ }
+ facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
- exit;
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
+ exit;
}
if ($action == 'down' && $user->rights->facture->creer)
{
- $object->fetch($id);
- $object->fetch_thirdparty();
- $object->line_down($_GET['rowid']);
+ $object->fetch($id);
+ $object->fetch_thirdparty();
+ $object->line_down($_GET['rowid']);
- // 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);
- }
- facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ // 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);
+ }
+ facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
- exit;
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'#'.$_GET['rowid']);
+ exit;
}
/*
@@ -1140,16 +1140,16 @@ if ($action == 'down' && $user->rights->facture->creer)
*/
if ($_POST['addfile'])
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+ require_once(DOL_DOCUMENT_ROOT."/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 = $vardir.'/temp/';
+ // Set tmp user directory TODO Use a dedicated directory for temp mails files
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir = $vardir.'/temp/';
- $mesg=dol_add_file_process($upload_dir,0,0);
+ $mesg=dol_add_file_process($upload_dir,0,0);
- $_GET["action"]='presend';
- $_POST["action"]='presend';
+ $_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -1157,16 +1157,16 @@ if ($_POST['addfile'])
*/
if (! empty($_POST['removedfile']))
{
- require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
+ require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
- // Set tmp user directory
- $vardir=$conf->user->dir_output."/".$user->id;
- $upload_dir = $vardir.'/temp/';
+ // Set tmp user directory
+ $vardir=$conf->user->dir_output."/".$user->id;
+ $upload_dir = $vardir.'/temp/';
- $mesg=dol_remove_file_process($_POST['removedfile'],0);
+ $mesg=dol_remove_file_process($_POST['removedfile'],0);
- $_GET["action"]='presend';
- $_POST["action"]='presend';
+ $_GET["action"]='presend';
+ $_POST["action"]='presend';
}
/*
@@ -1174,170 +1174,170 @@ if (! empty($_POST['removedfile']))
*/
if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
{
- $langs->load('mails');
+ $langs->load('mails');
- $actiontypecode='';$subject='';$actionmsg='';$actionmsg2='';
+ $actiontypecode='';$subject='';$actionmsg='';$actionmsg2='';
- $result=$object->fetch($id);
- $result=$object->fetch_thirdparty();
+ $result=$object->fetch($id);
+ $result=$object->fetch_thirdparty();
- if ($result > 0)
- {
- $ref = dol_sanitizeFileName($object->ref);
- $file = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf';
+ if ($result > 0)
+ {
+ $ref = dol_sanitizeFileName($object->ref);
+ $file = $conf->facture->dir_output . '/' . $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'])
- {
- // Le destinataire a ete fourni via la liste deroulante
- if ($_POST['receiver'] < 0) // Id du tiers
- {
- $sendto = $object->client->email;
- $sendtoid = 0;
- }
- else // Id du contact
- {
- $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
- $sendtoid = $_POST['receiver'];
- }
- }
+ if (is_readable($file))
+ {
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'])
+ {
+ // Le destinataire a ete fourni via la liste deroulante
+ if ($_POST['receiver'] < 0) // Id du tiers
+ {
+ $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");
+ 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'];
+ $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('Bill').' '.$object->ref;
- $actiontypecode='AC_FAC';
- $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);
- }
- if ($action == 'relance')
- {
- if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
- else $subject = $langs->transnoentities('Relance facture '.$object->ref);
- $actiontypecode='AC_FAC';
- $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);
- }
+ if ($action == 'send')
+ {
+ if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
+ else $subject = $langs->transnoentities('Bill').' '.$object->ref;
+ $actiontypecode='AC_FAC';
+ $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);
+ }
+ if ($action == 'relance')
+ {
+ if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
+ else $subject = $langs->transnoentities('Relance facture '.$object->ref);
+ $actiontypecode='AC_FAC';
+ $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);
+ // 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'];
+ $attachedfiles=$formmail->get_attached_files();
+ $filepath = $attachedfiles['paths'];
+ $filename = $attachedfiles['names'];
+ $mimetype = $attachedfiles['mimes'];
- // Send mail
- require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
- $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
- if ($mailfile->error)
- {
- $mesg=''.$mailfile->error.' ';
- }
- else
- {
- $result=$mailfile->sendfile();
- if ($result)
- {
- $mesg=$langs->trans('MailSuccessfulySent',$from,$sendto); // Must not contain "
+ // Send mail
+ require_once(DOL_DOCUMENT_ROOT.'/lib/CMailFile.class.php');
+ $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt,-1);
+ if ($mailfile->error)
+ {
+ $mesg=''.$mailfile->error.' ';
+ }
+ else
+ {
+ $result=$mailfile->sendfile();
+ if ($result)
+ {
+ $mesg=$langs->trans('MailSuccessfulySent',$from,$sendto); // Must not contain "
- $error=0;
+ $error=0;
- // Initialisation donnees
- $object->sendtoid=$sendtoid;
- $object->actiontypecode=$actiontypecode;
- $object->actionmsg = $actionmsg; // Long text
- $object->actionmsg2= $actionmsg2; // Short text
- $object->facid=$object->id;
+ // Initialisation donnees
+ $object->sendtoid=$sendtoid;
+ $object->actiontypecode=$actiontypecode;
+ $object->actionmsg = $actionmsg; // Long text
+ $object->actionmsg2= $actionmsg2; // Short text
+ $object->facid=$object->id;
- // Appel des triggers
- include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
- $interface=new Interfaces($db);
- $result=$interface->run_triggers('BILL_SENTBYMAIL',$object,$user,$langs,$conf);
- if ($result < 0) { $error++; $this->errors=$interface->errors; }
- // Fin appel triggers
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('BILL_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
- $_SESSION['message'] = $mesg;
- Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&mesg=1');
- exit;
- }
- }
- else
- {
- $langs->load("other");
- $mesg='';
- if ($mailfile->error)
- {
- $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
- $mesg.=' ';
- }
- }
- }
- else
- {
- $langs->load("other");
- $mesg=''.$mailfile->error; - } - else - { - $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; - } - $mesg.=' '.$langs->trans('ErrorMailRecipientIsEmpty').' ';
- dol_syslog('Recipient email is empty');
- }
- }
- else
- {
- $langs->load("other");
- $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('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
- }
+ if ($error)
+ {
+ dol_print_error($db);
+ }
+ else
+ {
+ // Redirect here
+ // This avoid sending mail twice if going out and then back to page
+ $_SESSION['message'] = $mesg;
+ Header('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&mesg=1');
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg='';
+ if ($mailfile->error)
+ {
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.=' ';
+ }
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.=' '.$langs->trans('ErrorMailRecipientIsEmpty').' ';
+ dol_syslog('Recipient email is empty');
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $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('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
+ }
- $action = 'presend';
+ $action = 'presend';
}
/*
@@ -1345,35 +1345,35 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO
*/
if (GETPOST('action') == 'builddoc') // En get ou en post
{
- $object->fetch($id);
- $object->fetch_thirdparty();
+ $object->fetch($id);
+ $object->fetch_thirdparty();
- if (GETPOST('model'))
- {
- $object->setDocModel($user, GETPOST('model'));
- }
+ if (GETPOST('model'))
+ {
+ $object->setDocModel($user, GETPOST('model'));
+ }
- // Define output language
- $outputlangs = $langs;
- $newlang='';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('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=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
- else
- {
- Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
- exit;
- }
+ // Define output language
+ $outputlangs = $langs;
+ $newlang='';
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('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=facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
+ else
+ {
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?facid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
+ exit;
+ }
}
@@ -1396,1126 +1396,1126 @@ $now=dol_now();
**********************************************************************/
if ($action == 'create')
{
- $facturestatic=new Facture($db);
+ $facturestatic=new Facture($db);
- print_fiche_titre($langs->trans('NewBill'));
+ print_fiche_titre($langs->trans('NewBill'));
- if ($mesg) print $mesg;
+ if ($mesg) print $mesg;
- $soc = new Societe($db);
+ $soc = new Societe($db);
if ($socid) $res=$soc->fetch($socid);
- if (GETPOST('origin') && GETPOST('originid'))
- {
- // Parse element/subelement (ex: project_task)
- $element = $subelement = GETPOST('origin');
- if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs))
- {
- $element = $regs[1];
- $subelement = $regs[2];
- }
+ if (GETPOST('origin') && GETPOST('originid'))
+ {
+ // Parse element/subelement (ex: project_task)
+ $element = $subelement = GETPOST('origin');
+ if (preg_match('/^([^_]+)_([^_]+)/i',GETPOST('origin'),$regs))
+ {
+ $element = $regs[1];
+ $subelement = $regs[2];
+ }
- if ($element == 'project')
- {
+ if ($element == 'project')
+ {
$projectid=GETPOST('originid');
- }
- else
- {
- // For compatibility
- if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
- if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
- if ($element == 'contract') { $element = $subelement = 'contrat'; }
+ }
+ else
+ {
+ // For compatibility
+ if ($element == 'order' || $element == 'commande') { $element = $subelement = 'commande'; }
+ if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; }
+ if ($element == 'contract') { $element = $subelement = 'contrat'; }
- dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
+ dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
- $classname = ucfirst($subelement);
- $objectsrc = new $classname($db);
- $objectsrc->fetch(GETPOST('originid'));
- if (empty($objectsrc->lines) && method_exists($objectsrc,'fetch_lines')) $objectsrc->fetch_lines();
- $objectsrc->fetch_thirdparty();
+ $classname = ucfirst($subelement);
+ $objectsrc = new $classname($db);
+ $objectsrc->fetch(GETPOST('originid'));
+ 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)?$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;
- }
- }
- else
- {
- $cond_reglement_id = $soc->cond_reglement_id;
- $mode_reglement_id = $soc->mode_reglement_id;
- $remise_percent = $soc->remise_percent;
- $remise_absolue = 0;
- $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
- }
- $absolute_discount=$soc->getAvailableDiscounts();
+ $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;
+ }
+ }
+ else
+ {
+ $cond_reglement_id = $soc->cond_reglement_id;
+ $mode_reglement_id = $soc->mode_reglement_id;
+ $remise_percent = $soc->remise_percent;
+ $remise_absolue = 0;
+ $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
+ }
+ $absolute_discount=$soc->getAvailableDiscounts();
- if ($conf->use_javascript_ajax)
- {
+ if ($conf->use_javascript_ajax)
+ {
print ajax_combobox('fac_replacement');
print ajax_combobox('fac_avoir');
- }
+ }
- print '\n";
+ print "\n";
- // Show origin lines
- if (is_object($objectsrc))
- {
- $title=$langs->trans('ProductsAndServices');
- print_titre($title);
+ // Show origin lines
+ if (is_object($objectsrc))
+ {
+ $title=$langs->trans('ProductsAndServices');
+ print_titre($title);
- print ''; + /* + * Show object in view mode + */ + if ($id > 0 || ! empty($ref)) + { + if ($mesg) print $mesg.' '; - $result=$object->fetch($id,$ref); - if ($result > 0) - { - if ($user->societe_id>0 && $user->societe_id!=$object->socid) accessforbidden('',0); + $result=$object->fetch($id,$ref); + if ($result > 0) + { + if ($user->societe_id>0 && $user->societe_id!=$object->socid) accessforbidden('',0); - $result=$object->fetch_thirdparty(); + $result=$object->fetch_thirdparty(); - $soc = new Societe($db, $object->socid); - $soc->fetch($object->socid); + $soc = new Societe($db, $object->socid); + $soc->fetch($object->socid); - $totalpaye = $object->getSommePaiement(); - $totalcreditnotes = $object->getSumCreditNotesUsed(); - $totaldeposits = $object->getSumDepositsUsed(); - //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits; + $totalpaye = $object->getSommePaiement(); + $totalcreditnotes = $object->getSumCreditNotesUsed(); + $totaldeposits = $object->getSumDepositsUsed(); + //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits; - // We can also use bcadd to avoid pb with floating points - // For example print 239.2 - 229.3 - 9.9; does not return 0. - //$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); - //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); - $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT'); + // We can also use bcadd to avoid pb with floating points + // For example print 239.2 - 229.3 - 9.9; does not return 0. + //$resteapayer=bcadd($object->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); + //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); + $resteapayer = price2num($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT'); - if ($object->paye) $resteapayer=0; - $resteapayeraffiche=$resteapayer; + if ($object->paye) $resteapayer=0; + $resteapayeraffiche=$resteapayer; - $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); - $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); - $absolute_discount=price2num($absolute_discount,'MT'); - $absolute_creditnote=price2num($absolute_creditnote,'MT'); + $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL'); + $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL'); + $absolute_discount=price2num($absolute_discount,'MT'); + $absolute_creditnote=price2num($absolute_creditnote,'MT'); - $author = new User($db); - if ($object->user_author) - { - $author->fetch($object->user_author); - } + $author = new User($db); + if ($object->user_author) + { + $author->fetch($object->user_author); + } - $objectidnext=$object->getIdReplacingInvoice(); + $objectidnext=$object->getIdReplacingInvoice(); - $head = facture_prepare_head($object); + $head = facture_prepare_head($object); - dol_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'), 0, 'bill'); + dol_fiche_head($head, 'compta', $langs->trans('InvoiceCustomer'), 0, 'bill'); - $formconfirm=''; + $formconfirm=''; - // Confirmation de la conversion de l'avoir en reduc - if ($action == 'converttoreduc') - { - $text=$langs->trans('ConfirmConvertToReduc'); - $formconfirm=$html->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('ConvertToReduc'),$text,'confirm_converttoreduc','',"yes",2); - } + // Confirmation de la conversion de l'avoir en reduc + if ($action == 'converttoreduc') + { + $text=$langs->trans('ConfirmConvertToReduc'); + $formconfirm=$html->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('ConvertToReduc'),$text,'confirm_converttoreduc','',"yes",2); + } - // Confirmation to delete invoice - if ($action == 'delete') - { - $text=$langs->trans('ConfirmDeleteBill'); - $formconfirm=$html->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('DeleteBill'),$text,'confirm_delete','',0,1); - } + // Confirmation to delete invoice + if ($action == 'delete') + { + $text=$langs->trans('ConfirmDeleteBill'); + $formconfirm=$html->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('DeleteBill'),$text,'confirm_delete','',0,1); + } - // Confirmation de la validation - if ($action == 'valid') - { - // on verifie si l'objet est en numerotation provisoire - $objectref = substr($object->ref, 1, 4); - if ($objectref == 'PROV') - { - $savdate=$object->date; - if (! empty($conf->global->FAC_FORCE_DATE_VALIDATION)) - { - $object->date=gmmktime(); - $object->date_lim_reglement=$object->calculate_date_lim_reglement(); - } - $numref = $object->getNextNumRef($soc); - //$object->date=$savdate; - } - else - { - $numref = $object->ref; - } + // Confirmation de la validation + if ($action == 'valid') + { + // on verifie si l'objet est en numerotation provisoire + $objectref = substr($object->ref, 1, 4); + if ($objectref == 'PROV') + { + $savdate=$object->date; + if (! empty($conf->global->FAC_FORCE_DATE_VALIDATION)) + { + $object->date=gmmktime(); + $object->date_lim_reglement=$object->calculate_date_lim_reglement(); + } + $numref = $object->getNextNumRef($soc); + //$object->date=$savdate; + } + else + { + $numref = $object->ref; + } - $text=$langs->trans('ConfirmValidateBill',$numref); - if ($conf->notification->enabled) - { - require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php"); - $notify=new Notify($db); - $text.=' '; - $text.=$notify->confirmMessage('NOTIFY_VAL_FAC',$object->socid); - } + $text=$langs->trans('ConfirmValidateBill',$numref); + if ($conf->notification->enabled) + { + require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php"); + $notify=new Notify($db); + $text.=' '; + $text.=$notify->confirmMessage('NOTIFY_VAL_FAC',$object->socid); + } - $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ValidateBill'),$text,'confirm_valid','',"yes",($conf->notification->enabled?0:2)); - } + $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ValidateBill'),$text,'confirm_valid','',"yes",($conf->notification->enabled?0:2)); + } - // Confirmation du classement paye - if ($action == 'paid' && $resteapayer <= 0) - { - $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ClassifyPaid'),$langs->trans('ConfirmClassifyPaidBill',$object->ref),'confirm_paid','',"yes",1); - } - if ($action == 'paid' && $resteapayer > 0) - { - // Code - $i=0; - $close[$i]['code']='discount_vat';$i++; - $close[$i]['code']='badcustomer';$i++; - // Help - $i=0; - $close[$i]['label']=$langs->trans("HelpEscompte").' '.$langs->trans("ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");$i++; - $close[$i]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");$i++; - // Texte - $i=0; - $close[$i]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonDiscountVat",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[$i]['label'],1);$i++; - $close[$i]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[$i]['label'],1);$i++; - // arrayreasons[code]=reason - foreach($close as $key => $val) - { - $arrayreasons[$close[$key]['code']]=$close[$key]['reason']; - } + // Confirmation du classement paye + if ($action == 'paid' && $resteapayer <= 0) + { + $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ClassifyPaid'),$langs->trans('ConfirmClassifyPaidBill',$object->ref),'confirm_paid','',"yes",1); + } + if ($action == 'paid' && $resteapayer > 0) + { + // Code + $i=0; + $close[$i]['code']='discount_vat';$i++; + $close[$i]['code']='badcustomer';$i++; + // Help + $i=0; + $close[$i]['label']=$langs->trans("HelpEscompte").' '.$langs->trans("ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");$i++; + $close[$i]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");$i++; + // Texte + $i=0; + $close[$i]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonDiscountVat",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[$i]['label'],1);$i++; + $close[$i]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$close[$i]['label'],1);$i++; + // arrayreasons[code]=reason + foreach($close as $key => $val) + { + $arrayreasons[$close[$key]['code']]=$close[$key]['reason']; + } - // Cree un tableau formulaire - $formquestion=array( + // Cree un tableau formulaire + $formquestion=array( 'text' => $langs->trans("ConfirmClassifyPaidPartiallyQuestion"), - array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons), - array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100') - ); - // Paiement incomplet. On demande si motif = escompte ou autre - $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ClassifyPaid'),$langs->trans('ConfirmClassifyPaidPartially',$object->ref),'confirm_paid_partially',$formquestion,"yes"); - } + array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons), + array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100') + ); + // Paiement incomplet. On demande si motif = escompte ou autre + $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ClassifyPaid'),$langs->trans('ConfirmClassifyPaidPartially',$object->ref),'confirm_paid_partially',$formquestion,"yes"); + } - // Confirmation du classement abandonne - if ($action == 'canceled') - { - // S'il y a une facture de remplacement pas encore validee (etat brouillon), - // on ne permet pas de classer abandonner la facture. - if ($objectidnext) - { - $facturereplacement=new Facture($db); - $facturereplacement->fetch($objectidnext); - $statusreplacement=$facturereplacement->statut; - } - if ($objectidnext && $statusreplacement == 0) - { - print ' '.$langs->trans("ErrorCantCancelIfReplacementInvoiceNotValidated").' ';
- }
- else
- {
- // Code
- $close[1]['code']='badcustomer';
- $close[2]['code']='abandon';
- // Help
- $close[1]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
- $close[2]['label']=$langs->trans("ConfirmClassifyAbandonReasonOtherDesc");
- // Texte
- $close[1]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$object->ref),$close[1]['label'],1);
- $close[2]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"),$close[2]['label'],1);
- // arrayreasons
- $arrayreasons[$close[1]['code']]=$close[1]['reason'];
- $arrayreasons[$close[2]['code']]=$close[2]['reason'];
+ // Confirmation du classement abandonne
+ if ($action == 'canceled')
+ {
+ // S'il y a une facture de remplacement pas encore validee (etat brouillon),
+ // on ne permet pas de classer abandonner la facture.
+ if ($objectidnext)
+ {
+ $facturereplacement=new Facture($db);
+ $facturereplacement->fetch($objectidnext);
+ $statusreplacement=$facturereplacement->statut;
+ }
+ if ($objectidnext && $statusreplacement == 0)
+ {
+ print ''.$langs->trans("ErrorCantCancelIfReplacementInvoiceNotValidated").' ';
+ }
+ else
+ {
+ // Code
+ $close[1]['code']='badcustomer';
+ $close[2]['code']='abandon';
+ // Help
+ $close[1]['label']=$langs->trans("ConfirmClassifyPaidPartiallyReasonBadCustomerDesc");
+ $close[2]['label']=$langs->trans("ConfirmClassifyAbandonReasonOtherDesc");
+ // Texte
+ $close[1]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer",$object->ref),$close[1]['label'],1);
+ $close[2]['reason']=$html->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"),$close[2]['label'],1);
+ // arrayreasons
+ $arrayreasons[$close[1]['code']]=$close[1]['reason'];
+ $arrayreasons[$close[2]['code']]=$close[2]['reason'];
- // Cree un tableau formulaire
- $formquestion=array(
+ // Cree un tableau formulaire
+ $formquestion=array(
'text' => $langs->trans("ConfirmCancelBillQuestion"),
- array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
- array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
- );
+ array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
+ array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
+ );
- $formconfirm=$html->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('CancelBill'),$langs->trans('ConfirmCancelBill',$object->ref),'confirm_canceled',$formquestion,"yes");
- }
- }
+ $formconfirm=$html->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id,$langs->trans('CancelBill'),$langs->trans('ConfirmCancelBill',$object->ref),'confirm_canceled',$formquestion,"yes");
+ }
+ }
- // Confirmation de la suppression d'une ligne produit
- if ($action == 'ask_deleteline')
- {
- $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
- }
+ // Confirmation de la suppression d'une ligne produit
+ if ($action == 'ask_deleteline')
+ {
+ $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
+ }
- // 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
- $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes',1);
- }
+ // 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
+ $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes',1);
+ }
- // Hook of thirdparty module
- if (empty($formconfirm) && ! empty($object->hooks))
- {
- foreach($object->hooks as $module)
- {
- if (empty($formconfirm)) $formconfirm = $module->formconfirm($action,$object,$lineid);
- }
- }
+ // Hook of thirdparty module
+ if (empty($formconfirm) && ! empty($object->hooks))
+ {
+ foreach($object->hooks as $module)
+ {
+ if (empty($formconfirm)) $formconfirm = $module->formconfirm($action,$object,$lineid);
+ }
+ }
- // Print form confirm
- print $formconfirm;
+ // Print form confirm
+ print $formconfirm;
- // Invoice content
+ // Invoice content
- print '
'; + print ' '; - /* - * Lines - */ + /* + * Lines + */ $result = $object->getLinesArray(); if ($conf->use_javascript_ajax && $object->statut == 0) @@ -2523,473 +2523,481 @@ else include(DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php'); } - print ' ';
+ if ($action != 'prerelance' && $action != 'presend')
+ {
+ if ($user->societe_id == 0 && $action <> 'valid' && $action <> 'editline')
+ {
+ print ' ';
+ }
+ }
- if ($action != 'prerelance' && $action != 'presend')
- {
- print '';
- // Editer une facture deja validee, sans paiement effectue et pas exporte en compta
- if ($object->statut == 1)
- {
- // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
- $ventilExportCompta = $object->getVentilExportCompta();
+ // Editer une facture deja validee, sans paiement effectue et pas exporte en compta
+ if ($object->statut == 1)
+ {
+ // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
+ $ventilExportCompta = $object->getVentilExportCompta();
- if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
- {
- if (! $objectidnext)
- {
- if ($user->rights->facture->unvalidate)
- {
- print ''.$langs->trans('Modify').'';
- }
- else
- {
- print ''.$langs->trans('Modify').'';
- }
- }
- else
- {
- print ''.$langs->trans('Modify').'';
- }
- }
- }
+ if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
+ {
+ if (! $objectidnext)
+ {
+ if ($user->rights->facture->unvalidate)
+ {
+ print ''.$langs->trans('Modify').'';
+ }
+ else
+ {
+ print ''.$langs->trans('Modify').'';
+ }
+ }
+ else
+ {
+ print ''.$langs->trans('Modify').'';
+ }
+ }
+ }
- // 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 (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice
- {
- print ''.$langs->trans('ReOpen').'';
- }
- else
- {
- print ''.$langs->trans('ReOpen').'';
- }
- }
+ // 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 (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice
+ {
+ print ''.$langs->trans('ReOpen').'';
+ }
+ else
+ {
+ print ''.$langs->trans('ReOpen').'';
+ }
+ }
- // Validate
- if ($object->statut == 0 && sizeof($object->lines) > 0 &&
- (
- (($object->type == 0 || $object->type == 1 || $object->type == 3 || $object->type == 4) && $object->total_ttc >= 0)
- || ($object->type == 2 && $object->total_ttc <= 0))
- )
- {
- if ($user->rights->facture->valider)
- {
- print 'id.'&action=valid"';
- print '>'.$langs->trans('Validate').'';
- }
- }
+ // Validate
+ if ($object->statut == 0 && sizeof($object->lines) > 0 &&
+ (
+ (($object->type == 0 || $object->type == 1 || $object->type == 3 || $object->type == 4) && $object->total_ttc >= 0)
+ || ($object->type == 2 && $object->total_ttc <= 0))
+ )
+ {
+ if ($user->rights->facture->valider)
+ {
+ print 'id.'&action=valid"';
+ print '>'.$langs->trans('Validate').'';
+ }
+ }
- // Send by mail
- if (($object->statut == 1 || $object->statut == 2) && $user->rights->facture->envoyer)
- {
- if ($objectidnext)
- {
- print ''.$langs->trans('SendByMail').'';
- }
- else
- {
- print ''.$langs->trans('SendByMail').'';
- }
- }
+ // Send by mail
+ if (($object->statut == 1 || $object->statut == 2))
+ {
+ if ($objectidnext)
+ {
+ print ''.$langs->trans('SendByMail').'';
+ }
+ else
+ {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
+ {
+ print ''.$langs->trans('SendByMail').'';
+ }
+ else print ''.$langs->trans('SendByMail').'';
+ }
+ }
- if ($conf->global->FACTURE_SHOW_SEND_REMINDER) // For backward compatibility
- {
- if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0 && $user->rights->facture->envoyer)
- {
- if ($objectidnext)
- {
- print ''.$langs->trans('SendRemindByMail').'';
- }
- else
- {
- print ''.$langs->trans('SendRemindByMail').'';
- }
- }
- }
+ if ($conf->global->FACTURE_SHOW_SEND_REMINDER) // For backward compatibility
+ {
+ if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0)
+ {
+ if ($objectidnext)
+ {
+ print ''.$langs->trans('SendRemindByMail').'';
+ }
+ else
+ {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send)
+ {
+ print ''.$langs->trans('SendRemindByMail').'';
+ }
+ else print ''.$langs->trans('SendRemindByMail').'';
+ }
+ }
+ }
- // Create payment
- if ($object->type != 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
- {
- if ($objectidnext)
- {
- print ''.$langs->trans('DoPayment').'';
- }
- else
- {
- if ($resteapayer == 0)
- {
- print ''.$langs->trans('DoPayment').'';
- }
- else
- {
- print ''.$langs->trans('DoPayment').'';
- }
- }
- }
+ // Create payment
+ if ($object->type != 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
+ {
+ if ($objectidnext)
+ {
+ print ''.$langs->trans('DoPayment').'';
+ }
+ else
+ {
+ if ($resteapayer == 0)
+ {
+ print ''.$langs->trans('DoPayment').'';
+ }
+ else
+ {
+ print ''.$langs->trans('DoPayment').'';
+ }
+ }
+ }
- // Reverse back money or convert to reduction
- if ($object->type == 2 || $object->type == 3)
- {
- // For credit note only
- if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
- {
- print ''.$langs->trans('DoPaymentBack').'';
- }
- // For credit note
- if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0)
- {
- print 'id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'';
- }
- // For deposit invoice
- if ($object->type == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer)
- {
- print 'id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'';
- }
- }
+ // Reverse back money or convert to reduction
+ if ($object->type == 2 || $object->type == 3)
+ {
+ // For credit note only
+ if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement)
+ {
+ print ''.$langs->trans('DoPaymentBack').'';
+ }
+ // For credit note
+ if ($object->type == 2 && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0)
+ {
+ print 'id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'';
+ }
+ // For deposit invoice
+ if ($object->type == 3 && $object->statut == 1 && $resteapayer == 0 && $user->rights->facture->creer)
+ {
+ print 'id.'&action=converttoreduc">'.$langs->trans('ConvertToReduc').'';
+ }
+ }
- // Classify paid (if not deposit and not credit note. Such invoice are "converted")
- if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement &&
- (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0)) )
- {
- print ''.$langs->trans('ClassifyPaid').'';
- }
+ // Classify paid (if not deposit and not credit note. Such invoice are "converted")
+ if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement &&
+ (($object->type != 2 && $object->type != 3 && $resteapayer <= 0) || ($object->type == 2 && $resteapayer >= 0)) )
+ {
+ print ''.$langs->trans('ClassifyPaid').'';
+ }
- // Classify 'closed not completely paid' (possible si validee et pas encore classee payee)
- if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0
- && $user->rights->facture->paiement)
- {
- if ($totalpaye > 0 || $totalcreditnotes > 0)
- {
- // If one payment or one credit note was linked to this invoice
- print ''.$langs->trans('ClassifyPaidPartially').'';
- }
- else
- {
- if ($objectidnext)
- {
- print ''.$langs->trans('ClassifyCanceled').'';
- }
- else
- {
- print ''.$langs->trans('ClassifyCanceled').'';
- }
- }
- }
+ // Classify 'closed not completely paid' (possible si validee et pas encore classee payee)
+ if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0
+ && $user->rights->facture->paiement)
+ {
+ if ($totalpaye > 0 || $totalcreditnotes > 0)
+ {
+ // If one payment or one credit note was linked to this invoice
+ print ''.$langs->trans('ClassifyPaidPartially').'';
+ }
+ else
+ {
+ if ($objectidnext)
+ {
+ print ''.$langs->trans('ClassifyCanceled').'';
+ }
+ else
+ {
+ print ''.$langs->trans('ClassifyCanceled').'';
+ }
+ }
+ }
- // Clone
- if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $user->rights->facture->creer)
- {
- print ''.$langs->trans("ToClone").'';
- }
+ // Clone
+ if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $user->rights->facture->creer)
+ {
+ print ''.$langs->trans("ToClone").'';
+ }
- // Clone as predefined
- if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $object->statut == 0 && $user->rights->facture->creer)
- {
- if (! $objectidnext)
- {
- print ''.$langs->trans("ChangeIntoRepeatableInvoice").'';
- }
- }
+ // Clone as predefined
+ if (($object->type == 0 || $object->type == 3 || $object->type == 4) && $object->statut == 0 && $user->rights->facture->creer)
+ {
+ if (! $objectidnext)
+ {
+ print ''.$langs->trans("ChangeIntoRepeatableInvoice").'';
+ }
+ }
- // Delete
- if ($user->rights->facture->supprimer)
- {
- if (! $object->is_erasable())
- {
- print ''.$langs->trans('Delete').'';
- }
- else if ($objectidnext)
- {
- print ''.$langs->trans('Delete').'';
- }
- elseif ($object->getSommePaiement())
- {
- print ''.$langs->trans('Delete').'';
- }
- else
- {
- print 'id.'&action=delete">'.$langs->trans('Delete').'';
- }
- }
- else
- {
- print ''.$langs->trans('Delete').'';
- }
+ // Delete
+ if ($user->rights->facture->supprimer)
+ {
+ if (! $object->is_erasable())
+ {
+ print ''.$langs->trans('Delete').'';
+ }
+ else if ($objectidnext)
+ {
+ print ''.$langs->trans('Delete').'';
+ }
+ elseif ($object->getSommePaiement())
+ {
+ print ''.$langs->trans('Delete').'';
+ }
+ else
+ {
+ print 'id.'&action=delete">'.$langs->trans('Delete').'';
+ }
+ }
+ else
+ {
+ print ''.$langs->trans('Delete').'';
+ }
- print ' ';
- }
- }
+ print ''; - print_titre($langs->trans($titre)); + print ' '; + print_titre($langs->trans($titre)); - // 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->transnoentities($topicmail,'__FACREF__'); - $formmail->withfile=2; - $formmail->withbody=1; - $formmail->withdeliveryreceipt=1; - $formmail->withcancel=1; - // Tableau des substitutions - $formmail->substit['__FACREF__']=$object->ref; - // Tableau des parametres complementaires du post - $formmail->param['action']=$action; - $formmail->param['models']=$modelmail; - $formmail->param['facid']=$object->id; - $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; + // 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->transnoentities($topicmail,'__FACREF__'); + $formmail->withfile=2; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + // Tableau des substitutions + $formmail->substit['__FACREF__']=$object->ref; + // Tableau des parametres complementaires du post + $formmail->param['action']=$action; + $formmail->param['models']=$modelmail; + $formmail->param['facid']=$object->id; + $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - // Init list of files - if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') - { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); - } + // Init list of files + if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,dol_sanitizeFilename($ref.'.pdf'),'application/pdf'); + } - $formmail->show_form(); + $formmail->show_form(); - print ' '; - } - } - else - { - dol_print_error($db,$object->error); - } - } - else - { - /*************************************************************************** - * * - * Mode Liste * - * * - ***************************************************************************/ - $now=dol_now(); + print ' '; + } + } + else + { + dol_print_error($db,$object->error); + } + } + else + { + /*************************************************************************** + * * + * Mode Liste * + * * + ***************************************************************************/ + $now=dol_now(); - $sortfield = GETPOST("sortfield",'alpha'); - $sortorder = GETPOST("sortorder",'alpha'); - $page = GETPOST("page",'int'); - if ($page == -1) { $page = 0; } - $offset = $conf->liste_limit * $page; - $pageprev = $page - 1; - $pagenext = $page + 1; + $sortfield = GETPOST("sortfield",'alpha'); + $sortorder = GETPOST("sortorder",'alpha'); + $page = GETPOST("page",'int'); + if ($page == -1) { $page = 0; } + $offset = $conf->liste_limit * $page; + $pageprev = $page - 1; + $pagenext = $page + 1; - $month =GETPOST('month','int'); - $year =GETPOST('year','int'); + $month =GETPOST('month','int'); + $year =GETPOST('year','int'); - $limit = $conf->liste_limit; - if (! $sortorder) $sortorder='DESC'; - if (! $sortfield) $sortfield='f.datef'; + $limit = $conf->liste_limit; + if (! $sortorder) $sortorder='DESC'; + if (! $sortfield) $sortfield='f.datef'; - $facturestatic=new Facture($db); + $facturestatic=new Facture($db); - if ($page == -1) $page = 0 ; + if ($page == -1) $page = 0 ; - $sql = 'SELECT '; - $sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,'; - $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; - $sql.= ' f.paye as paye, f.fk_statut,'; - $sql.= ' s.nom, s.rowid as socid'; + $sql = 'SELECT '; + $sql.= ' f.rowid as facid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,'; + $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; + $sql.= ' f.paye as paye, f.fk_statut,'; + $sql.= ' s.nom, s.rowid as socid'; if (! $sall) $sql.= ' ,SUM(pf.amount) as am'; // To be able to sort on status - $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= ', '.MAIN_DB_PREFIX.'facture as f'; - if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= ', '.MAIN_DB_PREFIX.'facture as f'; + if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid'; if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; - $sql.= ' WHERE f.fk_soc = s.rowid'; - $sql.= " AND f.entity = ".$conf->entity; - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) $sql.= ' AND s.rowid = '.$socid; - if ($_GET['filtre']) - { - $filtrearr = explode(',', $_GET['filtre']); - foreach ($filtrearr as $fil) - { - $filt = explode(':', $fil); - $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]); - } - } - if ($_GET['search_ref']) - { - $sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($_GET['search_ref'])).'%\''; - } - if ($_GET['search_societe']) - { - $sql.= ' AND s.nom LIKE \'%'.$db->escape(trim($_GET['search_societe'])).'%\''; - } - if ($_GET['search_montant_ht']) - { - $sql.= ' AND f.total = \''.$db->escape(trim($_GET['search_montant_ht'])).'\''; - } - if ($_GET['search_montant_ttc']) - { - $sql.= ' AND f.total_ttc = \''.$db->escape(trim($_GET['search_montant_ttc'])).'\''; - } - if ($month > 0) - { - if ($year > 0) - $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; - else - $sql.= " AND date_format(f.datef, '%m') = '".$month."'"; - } - else if ($year > 0) - { - $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; - } - if ($_POST['sf_ref']) - { - $sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($_POST['sf_ref'])) . '%\''; - } - if ($sall) - { - $sql.= ' AND (s.nom LIKE \'%'.$db->escape($sall).'%\' OR f.facnumber LIKE \'%'.$db->escape($sall).'%\' OR f.note LIKE \'%'.$db->escape($sall).'%\' OR fd.description LIKE \'%'.$db->escape($sall).'%\')'; - } + $sql.= ' WHERE f.fk_soc = s.rowid'; + $sql.= " AND f.entity = ".$conf->entity; + if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($socid) $sql.= ' AND s.rowid = '.$socid; + if ($_GET['filtre']) + { + $filtrearr = explode(',', $_GET['filtre']); + foreach ($filtrearr as $fil) + { + $filt = explode(':', $fil); + $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]); + } + } + if ($_GET['search_ref']) + { + $sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($_GET['search_ref'])).'%\''; + } + if ($_GET['search_societe']) + { + $sql.= ' AND s.nom LIKE \'%'.$db->escape(trim($_GET['search_societe'])).'%\''; + } + if ($_GET['search_montant_ht']) + { + $sql.= ' AND f.total = \''.$db->escape(trim($_GET['search_montant_ht'])).'\''; + } + if ($_GET['search_montant_ttc']) + { + $sql.= ' AND f.total_ttc = \''.$db->escape(trim($_GET['search_montant_ttc'])).'\''; + } + if ($month > 0) + { + if ($year > 0) + $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; + else + $sql.= " AND date_format(f.datef, '%m') = '".$month."'"; + } + else if ($year > 0) + { + $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; + } + if ($_POST['sf_ref']) + { + $sql.= ' AND f.facnumber LIKE \'%'.$db->escape(trim($_POST['sf_ref'])) . '%\''; + } + if ($sall) + { + $sql.= ' AND (s.nom LIKE \'%'.$db->escape($sall).'%\' OR f.facnumber LIKE \'%'.$db->escape($sall).'%\' OR f.note LIKE \'%'.$db->escape($sall).'%\' OR fd.description LIKE \'%'.$db->escape($sall).'%\')'; + } if (! $sall) { $sql.= ' GROUP BY f.rowid, f.facnumber, f.type, f.increment, f.total, f.total_ttc,'; @@ -2997,169 +3005,169 @@ else $sql.= ' f.paye, f.fk_statut,'; $sql.= ' s.nom, s.rowid'; } - $sql.= ' ORDER BY '; - $listfield=explode(',',$sortfield); - foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.','; - $sql.= ' f.rowid DESC '; - $sql.= $db->plimit($limit+1,$offset); + $sql.= ' ORDER BY '; + $listfield=explode(',',$sortfield); + foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.','; + $sql.= ' f.rowid DESC '; + $sql.= $db->plimit($limit+1,$offset); //print $sql; - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); - if ($socid) - { - $soc = new Societe($db); - $soc->fetch($socid); - } + if ($socid) + { + $soc = new Societe($db); + $soc->fetch($socid); + } - $param='&socid='.$socid; - if ($month) $param.='&month='.$month; - if ($year) $param.='&year=' .$year; + $param='&socid='.$socid; + if ($month) $param.='&month='.$month; + if ($year) $param.='&year=' .$year; - print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->nom:''),$page,'facture.php',$param,$sortfield,$sortorder,'',$num); + print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->nom:''),$page,'facture.php',$param,$sortfield,$sortorder,'',$num); - $i = 0; - print '\n"; + $db->free($resql); + } + else + { + dol_print_error($db); + } + } } $db->close(); diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 9d505e363a4..fd862164514 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -33,12 +33,12 @@ require_once(DOL_DOCUMENT_ROOT."/lib/fichinter.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/date.lib.php"); if ($conf->projet->enabled) { - require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); - require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); + require_once(DOL_DOCUMENT_ROOT."/lib/project.lib.php"); + require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php"); } if (! empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php")) { - require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php"); + require_once(DOL_DOCUMENT_ROOT ."/includes/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php"); } $langs->load("companies"); @@ -49,15 +49,17 @@ $fichinterid=0; $fichinter = new Fichinter($db); if ($_GET["id"] > 0 || ! empty($_GET["ref"])) { - $result=$fichinter->fetch($_GET["id"],$_GET["ref"]); - if (! $result > 0) - { - dol_print_error($db); - exit; - } - $fichinterid=$fichinter->id; + $result=$fichinter->fetch($_GET["id"],$_GET["ref"]); + if (! $result > 0) + { + dol_print_error($db); + exit; + } + $fichinterid=$fichinter->id; } +$mesg=GETPOST("msg"); + // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); @@ -70,115 +72,115 @@ $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); if ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && ! ($_REQUEST["id"] > 0) && empty($_REQUEST["ref"])) { - Header("Location: index.php"); - return; + Header("Location: index.php"); + return; } if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes') { - $fichinter = new Fichinter($db); - $fichinter->fetch($_GET["id"]); - $fichinter->fetch_thirdparty(); + $fichinter = new Fichinter($db); + $fichinter->fetch($_GET["id"]); + $fichinter->fetch_thirdparty(); - $result = $fichinter->setValid($user, $conf->fichinter->outputdir); - if ($result >= 0) - { - // 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=$fichinter->client->default_lang; - if (! empty($newlang)) - { - $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang($newlang); - } - $result=fichinter_create($db, $fichinter, $_REQUEST['model'], $outputlangs); - Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$fichinter->id); - exit; - } - else - { - $mesg=' '.$fichinter->error.' ';
- }
+ $result = $fichinter->setValid($user, $conf->fichinter->outputdir);
+ if ($result >= 0)
+ {
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $result=fichinter_create($db, $fichinter, $_REQUEST['model'], $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$fichinter->id);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$fichinter->error.' ';
+ }
}
if ($_REQUEST['action'] == 'confirm_modify' && $_REQUEST['confirm'] == 'yes')
{
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET["id"]);
- $fichinter->fetch_thirdparty();
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET["id"]);
+ $fichinter->fetch_thirdparty();
- $result = $fichinter->setDraft($user);
- if ($result >= 0)
- {
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $result=fichinter_create($db, $fichinter, (empty($_REQUEST['model'])?$fichinter->model:$_REQUEST['model']), $outputlangs);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$fichinter->id);
- exit;
- }
- else
- {
- $mesg=''.$fichinter->error.' ';
- }
+ $result = $fichinter->setDraft($user);
+ if ($result >= 0)
+ {
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $result=fichinter_create($db, $fichinter, (empty($_REQUEST['model'])?$fichinter->model:$_REQUEST['model']), $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$fichinter->id);
+ exit;
+ }
+ else
+ {
+ $mesg=''.$fichinter->error.' ';
+ }
}
if ($_POST["action"] == 'add')
{
- $fichinter = new Fichinter($db);
+ $fichinter = new Fichinter($db);
- $fichinter->socid = $_POST["socid"];
- $fichinter->duree = $_POST["duree"];
- $fichinter->fk_project = $_POST["projectid"];
- $fichinter->author = $user->id;
- $fichinter->description = $_POST["description"];
- $fichinter->ref = $_POST["ref"];
- $fichinter->modelpdf = $_POST["model"];
+ $fichinter->socid = $_POST["socid"];
+ $fichinter->duree = $_POST["duree"];
+ $fichinter->fk_project = $_POST["projectid"];
+ $fichinter->author = $user->id;
+ $fichinter->description = $_POST["description"];
+ $fichinter->ref = $_POST["ref"];
+ $fichinter->modelpdf = $_POST["model"];
- if ($fichinter->socid > 0)
- {
- $result = $fichinter->create();
- if ($result > 0)
- {
- $_GET["id"]=$result; // Force raffraichissement sur fiche venant d'etre cree
- $fichinterid=$result;
- }
- else
- {
- $langs->load("errors");
- $mesg=''.$langs->trans($fichinter->error).' ';
- $_GET["action"] = 'create';
- $_GET["socid"] = $_POST["socid"];
- }
- }
- else
- {
- $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).' ';
- $_GET["action"] = 'create';
- }
+ if ($fichinter->socid > 0)
+ {
+ $result = $fichinter->create();
+ if ($result > 0)
+ {
+ $_GET["id"]=$result; // Force raffraichissement sur fiche venant d'etre cree
+ $fichinterid=$result;
+ }
+ else
+ {
+ $langs->load("errors");
+ $mesg=''.$langs->trans($fichinter->error).' ';
+ $_GET["action"] = 'create';
+ $_GET["socid"] = $_POST["socid"];
+ }
+ }
+ else
+ {
+ $mesg=''.$langs->trans("ErrorFieldRequired",$langs->trans("ThirdParty")).' ';
+ $_GET["action"] = 'create';
+ }
}
if ($_POST["action"] == 'update')
{
- $fichinter = new Fichinter($db);
+ $fichinter = new Fichinter($db);
- $fichinter->socid = $_POST["socid"];
- $fichinter->fk_project = $_POST["projectid"];
- $fichinter->author = $user->id;
- $fichinter->description = $_POST["description"];
- $fichinter->ref = $_POST["ref"];
+ $fichinter->socid = $_POST["socid"];
+ $fichinter->fk_project = $_POST["projectid"];
+ $fichinter->author = $user->id;
+ $fichinter->description = $_POST["description"];
+ $fichinter->ref = $_POST["ref"];
- $fichinter->update($_POST["id"]);
- $_GET["id"]=$_POST["id"]; // Force raffraichissement sur fiche venant d'etre creee
+ $fichinter->update($_POST["id"]);
+ $_GET["id"]=$_POST["id"]; // Force raffraichissement sur fiche venant d'etre creee
}
/*
@@ -186,97 +188,97 @@ if ($_POST["action"] == 'update')
*/
if ($_REQUEST['action'] == 'builddoc') // En get ou en post
{
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET['id']);
- $fichinter->fetch_thirdparty();
- $fichinter->fetch_lines();
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET['id']);
+ $fichinter->fetch_thirdparty();
+ $fichinter->fetch_lines();
- if ($_REQUEST['model'])
- {
- $fichinter->setDocModel($user, $_REQUEST['model']);
- }
+ if ($_REQUEST['model'])
+ {
+ $fichinter->setDocModel($user, $_REQUEST['model']);
+ }
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $result=fichinter_create($db, $fichinter, $_REQUEST['model'], $outputlangs);
- if ($result <= 0)
- {
- dol_print_error($db,$result);
- exit;
- }
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ $result=fichinter_create($db, $fichinter, $_REQUEST['model'], $outputlangs);
+ if ($result <= 0)
+ {
+ dol_print_error($db,$result);
+ exit;
+ }
}
// Set into a project
if ($_POST['action'] == 'classin')
{
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET['id']);
- $result=$fichinter->setProject($_POST['projectid']);
- if ($result < 0) dol_print_error($db,$fichinter->error);
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET['id']);
+ $result=$fichinter->setProject($_POST['projectid']);
+ if ($result < 0) dol_print_error($db,$fichinter->error);
}
if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes')
{
- if ($user->rights->ficheinter->supprimer)
- {
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET['id']);
- $fichinter->delete($user);
- }
- Header('Location: index.php?leftmenu=ficheinter');
- exit;
+ if ($user->rights->ficheinter->supprimer)
+ {
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET['id']);
+ $fichinter->delete($user);
+ }
+ Header('Location: index.php?leftmenu=ficheinter');
+ exit;
}
if ($_POST['action'] == 'setdescription')
{
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET['id']);
- $result=$fichinter->set_description($user,$_POST['description']);
- if ($result < 0) dol_print_error($db,$fichinter->error);
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET['id']);
+ $result=$fichinter->set_description($user,$_POST['description']);
+ if ($result < 0) dol_print_error($db,$fichinter->error);
}
// Add line
if ($_POST['action'] == "addline" && $user->rights->ficheinter->creer)
{
- if ($_POST['np_desc'] && ($_POST['durationhour'] || $_POST['durationmin']))
- {
- $fichinter = new Fichinter($db);
- $ret=$fichinter->fetch($_POST['fichinterid']);
- $fichinter->fetch_thirdparty();
+ if ($_POST['np_desc'] && ($_POST['durationhour'] || $_POST['durationmin']))
+ {
+ $fichinter = new Fichinter($db);
+ $ret=$fichinter->fetch($_POST['fichinterid']);
+ $fichinter->fetch_thirdparty();
- $desc=$_POST['np_desc'];
- $date_intervention = dol_mktime($_POST["dihour"], $_POST["dimin"], 0, $_POST["dimonth"], $_POST["diday"], $_POST["diyear"]);
- $duration = ConvertTime2Seconds($_POST['durationhour'],$_POST['durationmin']);
+ $desc=$_POST['np_desc'];
+ $date_intervention = dol_mktime($_POST["dihour"], $_POST["dimin"], 0, $_POST["dimonth"], $_POST["diday"], $_POST["diyear"]);
+ $duration = ConvertTime2Seconds($_POST['durationhour'],$_POST['durationmin']);
- $fichinter->addline(
- $_POST['fichinterid'],
- $desc,
- $date_intervention,
- $duration
- );
+ $fichinter->addline(
+ $_POST['fichinterid'],
+ $desc,
+ $date_intervention,
+ $duration
+ );
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_POST['fichinterid']);
- exit;
- }
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_POST['fichinterid']);
+ exit;
+ }
}
/*
@@ -284,57 +286,57 @@ if ($_POST['action'] == "addline" && $user->rights->ficheinter->creer)
*/
if ($_POST['action'] == 'updateligne' && $user->rights->ficheinter->creer && $_POST["save"] == $langs->trans("Save"))
{
- $fichinterline = new FichinterLigne($db);
- if ($fichinterline->fetch($_POST['ligne']) <= 0)
- {
- dol_print_error($db);
- exit;
- }
+ $fichinterline = new FichinterLigne($db);
+ if ($fichinterline->fetch($_POST['ligne']) <= 0)
+ {
+ dol_print_error($db);
+ exit;
+ }
- $fichinter = new Fichinter($db);
- if ($fichinter->fetch($fichinterline->fk_fichinter) <= 0)
- {
- dol_print_error($db);
- exit;
- }
- $fichinter->fetch_thirdparty();
+ $fichinter = new Fichinter($db);
+ if ($fichinter->fetch($fichinterline->fk_fichinter) <= 0)
+ {
+ dol_print_error($db);
+ exit;
+ }
+ $fichinter->fetch_thirdparty();
- $desc=$_POST['np_desc'];
- $date_intervention = dol_mktime($_POST["dihour"], $_POST["dimin"], 0, $_POST["dimonth"], $_POST["diday"], $_POST["diyear"]);
- $duration = ConvertTime2Seconds($_POST['durationhour'],$_POST['durationmin']);
+ $desc=$_POST['np_desc'];
+ $date_intervention = dol_mktime($_POST["dihour"], $_POST["dimin"], 0, $_POST["dimonth"], $_POST["diday"], $_POST["diyear"]);
+ $duration = ConvertTime2Seconds($_POST['durationhour'],$_POST['durationmin']);
- $fichinterline->datei=$date_intervention;
- $fichinterline->desc=$desc;
- $fichinterline->duration=$duration;
- $result = $fichinterline->update();
- if ($result < 0)
- {
- dol_print_error($db);
- exit;
- }
+ $fichinterline->datei=$date_intervention;
+ $fichinterline->desc=$desc;
+ $fichinterline->duration=$duration;
+ $result = $fichinterline->update();
+ if ($result < 0)
+ {
+ dol_print_error($db);
+ exit;
+ }
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
- unset($_POST['dihour']);
- unset($_POST['dimin']);
- unset($_POST['dimonth']);
- $dateintervention='';
- unset($_POST['np_desc']);
- unset($_POST['durationhour']);
- unset($_POST['durationmin']);
+ unset($_POST['dihour']);
+ unset($_POST['dimin']);
+ unset($_POST['dimonth']);
+ $dateintervention='';
+ unset($_POST['np_desc']);
+ unset($_POST['durationhour']);
+ unset($_POST['durationmin']);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_POST['fichinterid']);
- exit;
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_POST['fichinterid']);
+ exit;
}
/*
@@ -342,36 +344,36 @@ if ($_POST['action'] == 'updateligne' && $user->rights->ficheinter->creer && $_P
*/
if ($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes')
{
- if ($user->rights->ficheinter->creer)
- {
- $fichinterline = new FichinterLigne($db);
- if ($fichinterline->fetch($_GET['ligne']) <= 0)
- {
- dol_print_error($db);
- exit;
- }
- $result=$fichinterline->deleteline();
- $fichinter = new Fichinter($db);
- if ($fichinter->fetch($fichinterline->fk_fichinter) <= 0)
- {
- dol_print_error($db);
- exit;
- }
+ if ($user->rights->ficheinter->creer)
+ {
+ $fichinterline = new FichinterLigne($db);
+ if ($fichinterline->fetch($_GET['ligne']) <= 0)
+ {
+ dol_print_error($db);
+ exit;
+ }
+ $result=$fichinterline->deleteline();
+ $fichinter = new Fichinter($db);
+ if ($fichinter->fetch($fichinterline->fk_fichinter) <= 0)
+ {
+ dol_print_error($db);
+ exit;
+ }
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
- }
- Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
- exit;
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
+ }
+ Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET['id']);
+ exit;
}
/*
@@ -380,46 +382,199 @@ if ($_REQUEST['action'] == 'confirm_deleteline' && $_REQUEST['confirm'] == 'yes'
if ($_GET['action'] == 'up' && $user->rights->ficheinter->creer)
{
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET['id']);
- $fichinter->fetch_thirdparty();
- $fichinter->line_up($_GET['rowid']);
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET['id']);
+ $fichinter->fetch_thirdparty();
+ $fichinter->line_up($_GET['rowid']);
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
- exit;
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ exit;
}
if ($_GET['action'] == 'down' && $user->rights->ficheinter->creer)
{
- $fichinter = new Fichinter($db);
- $fichinter->fetch($_GET['id']);
- $fichinter->fetch_thirdparty();
- $fichinter->line_down($_GET['rowid']);
+ $fichinter = new Fichinter($db);
+ $fichinter->fetch($_GET['id']);
+ $fichinter->fetch_thirdparty();
+ $fichinter->line_down($_GET['rowid']);
- // 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=$fichinter->client->default_lang;
- if (! empty($newlang))
- {
- $outputlangs = new Translate("",$conf);
- $outputlangs->setDefaultLang($newlang);
- }
- fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
- Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
- exit;
+ // 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=$fichinter->client->default_lang;
+ if (! empty($newlang))
+ {
+ $outputlangs = new Translate("",$conf);
+ $outputlangs->setDefaultLang($newlang);
+ }
+ fichinter_create($db, $fichinter, $fichinter->modelpdf, $outputlangs);
+ Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'#'.$_GET['rowid']);
+ exit;
+}
+
+/*
+ * Send mail
+ */
+if ($_POST['action'] == 'send' && ! $_POST['cancel'] && (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send))
+{
+ $langs->load('mails');
+
+ $fichinter = new Fichinter($db);
+ if ( $fichinter->fetch($_POST['fichinter_id']) )
+ {
+ $ficheinterref = dol_sanitizeFileName($fichinter->ref);
+ $file = $conf->ficheinter->dir_output . '/' . $ficheinterref . '/' . $ficheinterref . '.pdf';
+
+ if (is_readable($file))
+ {
+ $fichinter->fetch_thirdparty();
+
+ if ($_POST['sendto'])
+ {
+ // Le destinataire a ete fourni via le champ libre
+ $sendto = $_POST['sendto'];
+ $sendtoid = 0;
+ }
+ elseif ($_POST['receiver'])
+ {
+ // Le destinataire a ete fourni via la liste deroulante
+ if ($_POST['receiver'] < 0) // Id du tiers
+ {
+ $sendto = $fichinter->client->email;
+ $sendtoid = 0;
+ }
+ else // Id du contact
+ {
+ $sendto = $fichinter->client->contact_get_email($_POST['receiver']);
+ $sendtoid = $_POST['receiver'];
+ }
+ }
+
+ if (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 ($_POST['action'] == 'send')
+ {
+ if (strlen($_POST['subject'])) $subject = $_POST['subject'];
+ else $subject = $langs->transnoentities('Intervention').' '.$fichinter->ref;
+ $actiontypecode='AC_FICH';
+ $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'];
+
+ // Envoi de la propal
+ require_once(DOL_DOCUMENT_ROOT.'/lib/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',$from,$sendto).'. ';
+
+ $error=0;
+
+ // Initialisation donnees
+ $fichinter->sendtoid=$sendtoid;
+ $fichinter->actiontypecode=$actiontypecode;
+ $fichinter->actionmsg = $actionmsg;
+ $fichinter->actionmsg2= $actionmsg2;
+ $fichinter->rowid=$fichinter->id;
+
+ // Appel des triggers
+ include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
+ $interface=new Interfaces($db);
+ $result=$interface->run_triggers('FICHINTER_SENTBYMAIL',$fichinter,$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='.$fichinter->id.'&msg='.urlencode($mesg));
+ exit;
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg='';
+ if ($mailfile->error)
+ {
+ $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
+ $mesg.=' ';
+ }
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$mailfile->error; + } + else + { + $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; + } + $mesg.=' '.$langs->trans('ErrorMailRecipientIsEmpty').' ! ';
+ dol_syslog('Recipient email is empty');
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorCantReadFile',$file).' ';
+ dol_syslog('Failed to read file: '.$file);
+ }
+ }
+ else
+ {
+ $langs->load("other");
+ $mesg=''.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Intervention")).' ';
+ dol_syslog('Impossible de lire les donnees de l\'intervention. Le fichier intervention n\'a peut-etre pas ete genere.');
+ }
}
@@ -434,473 +589,541 @@ llxHeader();
if ($_GET["action"] == 'create')
{
- /*
- * Mode creation
- * Creation d'une nouvelle fiche d'intervention
- */
+ /*
+ * Mode creation
+ * Creation d'une nouvelle fiche d'intervention
+ */
- $societe=new Societe($db);
- if ($_GET["socid"] > 0)
- {
- $societe->fetch($_GET["socid"]);
- }
+ $societe=new Societe($db);
+ if ($_GET["socid"] > 0)
+ {
+ $societe->fetch($_GET["socid"]);
+ }
- print_fiche_titre($langs->trans("AddIntervention"));
+ print_fiche_titre($langs->trans("AddIntervention"));
- if ($mesg) print $mesg.''; + if ($mesg) print $mesg.' '; - if (! $conf->global->FICHEINTER_ADDON) - { - dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined")); - exit; - } + if (! $conf->global->FICHEINTER_ADDON) + { + dol_print_error($db,$langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined")); + exit; + } - $ficheinter = new Fichinter($db); - $ficheinter->date = time(); - if ($fichinterid) $result=$ficheinter->fetch($fichinterid); + $ficheinter = new Fichinter($db); + $ficheinter->date = time(); + if ($fichinterid) $result=$ficheinter->fetch($fichinterid); - $obj = $conf->global->FICHEINTER_ADDON; - $obj = "mod_".$obj; + $obj = $conf->global->FICHEINTER_ADDON; + $obj = "mod_".$obj; - $modFicheinter = new $obj; - $numpr = $modFicheinter->getNextValue($societe,$ficheinter); + $modFicheinter = new $obj; + $numpr = $modFicheinter->getNextValue($societe,$ficheinter); - if ($_GET["socid"] > 0) - { - print '
'; - print ''; - print ' '; + print ''; + print '
"; + if ($mesg) dol_htmloutput_errors($mesg)." "; - $head = fichinter_prepare_head($fichinter); + $head = fichinter_prepare_head($fichinter); - dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention'); + dol_fiche_head($head, 'card', $langs->trans("InterventionCard"), 0, 'intervention'); - // Confirmation de la suppression de la fiche d'intervention - if ($_GET['action'] == 'delete') - { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1); - if ($ret == 'html') print ' '; - } + // Confirmation de la suppression de la fiche d'intervention + if ($_GET['action'] == 'delete') + { + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete','',0,1); + if ($ret == 'html') print ' '; + } - // Confirmation validation - if ($_GET['action'] == 'validate') - { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('ValidateIntervention'), $langs->trans('ConfirmValidateIntervention'), 'confirm_validate','',0,1); - if ($ret == 'html') print ' '; - } + // Confirmation validation + if ($_GET['action'] == 'validate') + { + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('ValidateIntervention'), $langs->trans('ConfirmValidateIntervention'), 'confirm_validate','',0,1); + if ($ret == 'html') print ' '; + } - // Confirmation de la validation de la fiche d'intervention - if ($_GET['action'] == 'modify') - { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1); - if ($ret == 'html') print ' '; - } + // Confirmation de la validation de la fiche d'intervention + if ($_GET['action'] == 'modify') + { + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify','',0,1); + if ($ret == 'html') print ' '; + } - // Confirmation de la suppression d'une ligne d'intervention - if ($_GET['action'] == 'ask_deleteline') - { - $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&ligne='.$_GET["ligne"], $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1); - if ($ret == 'html') print ' '; - } + // Confirmation de la suppression d'une ligne d'intervention + if ($_GET['action'] == 'ask_deleteline') + { + $ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id.'&ligne='.$_GET["ligne"], $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline','',0,1); + if ($ret == 'html') print ' '; + } - print '
';
+ if ($_GET['action'] == 'classin')
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, $fichinter->fk_project,'projectid');
+ }
+ else
+ {
+ $html->form_project($_SERVER['PHP_SELF'].'?id='.$fichinter->id, $fichinter->socid, $fichinter->fk_project,'none');
+ }
+ print ' | ';
+ print '';
+ }
- // Statut
- print ''.$langs->trans("Status").' | '.$fichinter->getLibStatut(4).' | '.$langs->trans("Status").' | '.$fichinter->getLibStatut(4).' |
';
+ /*
+ * Barre d'actions
+ */
+ print ' ';
- if ($user->societe_id == 0)
- {
- if ($_GET['action'] != 'editdescription')
- {
- // Validate
- if ($fichinter->statut == 0 && $user->rights->ficheinter->creer)
- {
- print ''.$langs->trans("Valid").'';
- }
+ if ($user->societe_id == 0)
+ {
+ if ($_GET['action'] != 'editdescription')
+ {
+ // Validate
+ if ($fichinter->statut == 0 && $user->rights->ficheinter->creer)
+ {
+ print ''.$langs->trans("Valid").'';
+ }
- // Modify
- if ($fichinter->statut == 1 && $user->rights->ficheinter->creer)
- {
- print ''.$langs->trans("Modify").'';
- }
+ // Modify
+ if ($fichinter->statut == 1 && $user->rights->ficheinter->creer)
+ {
+ print ''.$langs->trans("Modify").'';
+ }
- // Delete
- if (($fichinter->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
- {
- print 'id.'&action=delete"';
- print '>'.$langs->trans('Delete').'';
- }
- }
- }
+ // Send
+ if ($fichinter->statut == 1)
+ {
+ $ficheinterref = dol_sanitizeFileName($fichinter->ref);
+ $file = $conf->ficheinter->dir_output . '/'.$ficheinterref.'/'.$ficheinterref.'.pdf';
+ if (file_exists($file))
+ {
+ if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send)
+ {
+ print 'id.'&action=presend&mode=init">'.$langs->trans('SendByMail').'';
+ }
+ else print ''.$langs->trans('SendByMail').'';
+ }
+ }
- print ' ';
+ // Delete
+ if (($fichinter->statut == 0 && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer)
+ {
+ print 'id.'&action=delete"';
+ print '>'.$langs->trans('Delete').'';
+ }
+ }
+ }
- print '
'; + print_titre($langs->trans('SendInterventionByMail')); + + // Create form object + 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->fullname; + $formmail->frommail = $user->email; + $formmail->withfrom=1; + $formmail->withto=empty($_POST["sendto"])?1:$_POST["sendto"]; + $formmail->withtosocid=$societe->id; + $formmail->withtocc=1; + $formmail->withtoccsocid=0; + $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; + $formmail->withtocccsocid=0; + $formmail->withtopic=$langs->trans('SendInterventionRef','__FICHREF__'); + $formmail->withfile=1; + $formmail->withbody=1; + $formmail->withdeliveryreceipt=1; + $formmail->withcancel=1; + + // Tableau des substitutions + $formmail->substit['__FICHREF__']=$fichinter->ref; + // Tableau des parametres complementaires + $formmail->param['action']='send'; + $formmail->param['models']='fichinter_send'; + $formmail->param['fichinter_id']=$fichinter->id; + $formmail->param['returnurl']=DOL_URL_ROOT.'/fichinter/fiche.php?id='.$fichinter->id; + + // Init list of files + if (! empty($_REQUEST["mode"]) && $_REQUEST["mode"]=='init') + { + $formmail->clear_attached_files(); + $formmail->add_attached_files($file,$fichinter->ref.'.pdf','application/pdf'); + } + + $formmail->show_form(); + + print ' '; + } + + + print '
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||