';
+ if ($fac->paye) $resteapayer=0;
+ $resteapayeraffiche=$resteapayer;
- // Ref
- print '| '.$langs->trans("Ref").' | ';
- $morehtmlref='';
- $discount=new DiscountAbsolute($db);
- $result=$discount->fetch(0,$fac->id);
- if ($result > 0)
- {
- $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
- }
- if ($result < 0)
- {
- dol_print_error('',$discount->error);
- }
- print $html->showrefnav($fac,'ref','',1,'facnumber','ref',$morehtmlref);
- print " |
";
+ $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');
- // Societe
- print '| '.$langs->trans("Company").' | ';
- print ''.$soc->getNomUrl(1,'compta');
- print ' | ';
- print '
';
+ $author = new User($db);
+ if ($fac->user_author)
+ {
+ $author->fetch($fac->user_author);
+ }
- // Dates
- print '| '.$langs->trans("Date").' | ';
- print ''.dol_print_date($fac->date,"daytext").' | ';
- print ''.$langs->trans("DateMaxPayment").' | ' . dol_print_date($fac->date_lim_reglement,"daytext");
- if ($fac->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans("Late"));
- print " |
";
+ $head = facture_prepare_head($fac);
- // Conditions et modes de r�glement
- print '| '.$langs->trans("PaymentConditions").' | ';
- $html->form_conditions_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->cond_reglement_id,"none");
- print ' | ';
- print ''.$langs->trans("PaymentMode").' | ';
- $html->form_modes_reglement($_SERVER["PHP_SELF"]."?facid=$fac->id",$fac->mode_reglement_id,"none");
- print ' |
';
+ dol_fiche_head($head, 'standingorders', $langs->trans('InvoiceCustomer'),0,'bill');
- print '| '.$langs->trans("AmountHT").' | ';
- print ''.price($fac->total_ht).' | ';
- print ''.$langs->trans("Currency".$conf->monnaie).' | |
';
+ /*
+ * Facture
+ */
+ print '';
- print '| '.$langs->trans("AmountTTC").' | ';
- print ''.price($fac->total_ttc).' | ';
- print ''.$langs->trans("Currency".$conf->monnaie).' | |
';
+ // Ref
+ print '| '.$langs->trans("Ref").' | ';
+ $morehtmlref='';
+ $discount=new DiscountAbsolute($db);
+ $result=$discount->fetch(0,$fac->id);
+ if ($result > 0)
+ {
+ $morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
+ }
+ if ($result < 0)
+ {
+ dol_print_error('',$discount->error);
+ }
+ print $html->showrefnav($fac,'ref','',1,'facnumber','ref',$morehtmlref);
+ print " |
";
- print '| '.$langs->trans("RIB").' | ';
- print $soc->display_rib();
- print ' |
';
+ // Third party
+ print '| '.$langs->trans('Company').' | ';
+ print ''.$soc->getNomUrl(1,'compta');
+ print ' ('.$langs->trans('OtherBills').') | ';
+ print '
';
- print '
';
- print '';
+ // Type
+ print '| '.$langs->trans('Type').' | ';
+ print $fac->getLibType();
+ if ($fac->type == 1)
+ {
+ $facreplaced=new Facture($db);
+ $facreplaced->fetch($fac->fk_facture_source);
+ print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
+ }
+ if ($fac->type == 2)
+ {
+ $facusing=new Facture($db);
+ $facusing->fetch($fac->fk_facture_source);
+ print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
+ }
- /*
- * Withdrawal request
- */
+ $facidavoir=$fac->getListIdAvoirFromInvoice();
+ if (sizeof($facidavoir) > 0)
+ {
+ print ' ('.$langs->transnoentities("InvoiceHasAvoir");
+ $i=0;
+ foreach($facidavoir as $id)
+ {
+ if ($i==0) print ' ';
+ else print ',';
+ $facavoir=new Facture($db);
+ $facavoir->fetch($id);
+ print $facavoir->getNomUrl(1);
+ }
+ print ')';
+ }
+ if ($facidnext > 0)
+ {
+ $facthatreplace=new Facture($db);
+ $facthatreplace->fetch($facidnext);
+ print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
+ }
+ print ' |
';
- $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
- $sql .= " , pfd.date_traite as date_traite";
- $sql .= " , pfd.amount";
- $sql .= " , u.rowid as user_id, u.name, u.firstname, u.login";
- $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
- $sql .= " , ".MAIN_DB_PREFIX."user as u";
- $sql .= " WHERE fk_facture = ".$fac->id;
- $sql .= " AND pfd.fk_user_demande = u.rowid";
- $sql .= " AND pfd.traite = 0";
- $sql .= " ORDER BY pfd.date_demande DESC";
+ // Discounts
+ print '| '.$langs->trans('Discounts').' | ';
+ if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
+ else print $langs->trans("CompanyHasNoRelativeDiscount");
+ print '. ';
+ if ($absolute_discount > 0)
+ {
+ if ($fac->statut > 0 || $fac->type == 2 || $fac->type == 3)
+ {
+ if ($fac->statut == 0)
+ {
+ print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)).'. ';
+ }
+ else
+ {
+ if ($fac->statut < 1 || $fac->type == 2 || $fac->type == 3)
+ {
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
+ print ' '.$text.'. ';
+ }
+ else
+ {
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
+ $text2=$langs->trans("AbsoluteDiscountUse");
+ print $html->textwithpicto($text,$text2);
+ }
+ }
+ }
+ else
+ {
+ // Remise dispo de type non avoir
+ $filter='fk_facture_source IS NULL';
+ print ' ';
+ $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id',$soc->id,$absolute_discount,$filter,$resteapayer);
+ }
+ }
+ if ($absolute_creditnote > 0)
+ {
+ // If validated, we show link "add credit note to payment"
+ if ($fac->statut != 1 || $fac->type == 2 || $fac->type == 3)
+ {
+ if ($fac->statut == 0 && $fac->type != 3)
+ {
+ $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie));
+ print $html->textwithpicto($text,$langs->trans("CreditNoteDepositUse"));
+ }
+ else print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.';
+ }
+ else
+ {
+ // Remise dispo de type avoir
+ $filter='fk_facture_source IS NOT NULL';
+ if (! $absolute_discount) print ' ';
+ $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$fac->id,0,'remise_id_for_payment',$soc->id,$absolute_creditnote,$filter,$resteapayer);
+ }
+ }
+ if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
+ print ' |
';
- $result_sql = $db->query($sql);
- if ($result_sql)
- {
- $num = $db->num_rows($result_sql);
- }
+ // Date invoice
+ print '| ';
+ print '';
+ print ' | ';
+
+ if ($fac->type != 2)
+ {
+ if ($_GET['action'] == 'editinvoicedate')
+ {
+ $html->form_date($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->date,'invoicedate');
+ }
+ else
+ {
+ print dol_print_date($fac->date,'daytext');
+ }
+ }
+ else
+ {
+ print dol_print_date($fac->date,'daytext');
+ }
+ print ' | ';
+ print '
';
+
+ // Date payment term
+ print '';
+ print '| ';
+ print $langs->trans('DateMaxPayment');
+ print ' | ';
+ if ($fac->type != 2 && $_GET['action'] != 'editpaymentterm' && $fac->brouillon && $user->rights->facture->creer) print 'id.'">'.img_edit($langs->trans('SetDate'),1).' | ';
+ print ' ';
+ print ' | ';
+ if ($fac->type != 2)
+ {
+ if ($_GET['action'] == 'editpaymentterm')
+ {
+ $html->form_date($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->date_lim_reglement,'paymentterm');
+ }
+ else
+ {
+ print dol_print_date($fac->date_lim_reglement,'daytext');
+ if ($fac->date_lim_reglement < ($now - $conf->facture->client->warning_delay) && ! $fac->paye && $fac->statut == 1 && ! $fac->am) print img_warning($langs->trans('Late'));
+ }
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' |
';
+
+ // Conditions de reglement
+ print '| ';
+ print '';
+ print ' | ';
+ if ($fac->type != 2)
+ {
+ if ($_GET['action'] == 'editconditions')
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'cond_reglement_id');
+ }
+ else
+ {
+ $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->cond_reglement_id,'none');
+ }
+ }
+ else
+ {
+ print ' ';
+ }
+ print ' |
';
+
+ // Mode de reglement
+ print '| ';
+ print '';
+ print ' | ';
+ if ($_GET['action'] == 'editmode')
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'mode_reglement_id');
+ }
+ else
+ {
+ $html->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$fac->id,$fac->mode_reglement_id,'none');
+ }
+ print ' |
';
+
+ // Montants
+ print '| '.$langs->trans('AmountHT').' | ';
+ print ''.price($fac->total_ht).' | ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' |
';
+ print '| '.$langs->trans('AmountVAT').' | '.price($fac->total_tva).' | ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' |
';
+
+ // Amount Local Taxes
+ if ($mysoc->pays_code=='ES')
+ {
+ if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
+ {
+ print '| '.$langs->transcountry("AmountLT1",$mysoc->pays_code).' | ';
+ print ''.price($fac->total_localtax1).' | ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' |
';
+ }
+ if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
+ {
+ print '| '.$langs->transcountry("AmountLT2",$mysoc->pays_code).' | ';
+ print ''.price($fac->total_localtax2).' | ';
+ print ''.$langs->trans("Currency".$conf->monnaie).' |
';
+ }
+ }
+
+ print '| '.$langs->trans('AmountTTC').' | '.price($fac->total_ttc).' | ';
+ print ''.$langs->trans('Currency'.$conf->monnaie).' |
';
+
+ // Statut
+ print '| '.$langs->trans('Status').' | ';
+ print ''.($fac->getLibStatut(4,$totalpaye)).' |
';
+
+ print '| '.$langs->trans("RIB").' | ';
+ print $soc->display_rib();
+ print ' |
';
+
+ print '
';
+
+ dol_fiche_end();
- /*
- * Buttons
- */
- print "\n";
+ /*
+ * Withdrawal request
+ */
- // Add a withdraw request
- if ($fac->statut > 0 && $fac->paye == 0 && $num == 0)
- {
- if ($user->rights->prelevement->bons->configurer)
- {
- print '
'.$langs->trans("MakeWithdrawRequest").'';
- }
- else
- {
- print '
'.$langs->trans("MakeWithdrawRequest").'';
- }
- }
+ $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
+ $sql .= " , pfd.date_traite as date_traite";
+ $sql .= " , pfd.amount";
+ $sql .= " , u.rowid as user_id, u.name, u.firstname, u.login";
+ $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
+ $sql .= " , ".MAIN_DB_PREFIX."user as u";
+ $sql .= " WHERE fk_facture = ".$fac->id;
+ $sql .= " AND pfd.fk_user_demande = u.rowid";
+ $sql .= " AND pfd.traite = 0";
+ $sql .= " ORDER BY pfd.date_demande DESC";
- print "