public function exists(Facture $facture)
 {
     $q = $this->_db->prepare('SELECT COUNT(*) FROM facture WHERE idFacture = :idFacture');
     $q->bindValue(':idFacture', $facture->idFacture(), PDO::PARAM_INT);
     $q->execute();
     return (bool) $q->fetchColumn();
 }
Beispiel #2
0
 /**
  *  Load data into info_box_contents array to show array later.
  *
  *  @param	int		$max        Maximum number of records to load
  *  @return	void
  */
 function loadBox($max = 5)
 {
     global $conf, $user, $langs, $db;
     $this->max = $max;
     include_once DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php";
     $facturestatic = new Facture($db);
     $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestUnpaidCustomerBills", $max));
     if ($user->rights->facture->lire) {
         $sql = "SELECT s.nom, s.rowid as socid,";
         $sql .= " f.facnumber, f.date_lim_reglement as datelimite,";
         $sql .= " f.amount, f.datef as df,";
         $sql .= " f.paye, f.fk_statut, f.rowid as facid";
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s," . MAIN_DB_PREFIX . "facture as f";
         if (!$user->rights->societe->client->voir && !$user->societe_id) {
             $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
         }
         $sql .= " WHERE f.fk_soc = s.rowid";
         $sql .= " AND f.entity = " . $conf->entity;
         $sql .= " AND f.paye = 0";
         $sql .= " AND fk_statut = 1";
         if (!$user->rights->societe->client->voir && !$user->societe_id) {
             $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = " . $user->societe_id;
         }
         //$sql.= " ORDER BY f.datef DESC, f.facnumber DESC ";
         $sql .= " ORDER BY datelimite ASC, f.facnumber ASC ";
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $num = $db->num_rows($result);
             $now = dol_now();
             $i = 0;
             $l_due_date = $langs->trans('Late') . ' (' . strtolower($langs->trans('DateEcheance')) . ': %s)';
             while ($i < $num) {
                 $objp = $db->fetch_object($result);
                 $datelimite = $db->jdate($objp->datelimite);
                 $late = '';
                 if ($datelimite < $now - $conf->facture->client->warning_delay) {
                     $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day')));
                 }
                 $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"', 'logo' => $this->boximg, 'url' => DOL_URL_ROOT . "/compta/facture.php?facid=" . $objp->facid);
                 $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->facnumber, 'text2' => $late, 'url' => DOL_URL_ROOT . "/compta/facture.php?facid=" . $objp->facid);
                 $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid);
                 $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => $objp->nom, 'maxlength' => 44, 'url' => DOL_URL_ROOT . "/comm/fiche.php?socid=" . $objp->socid);
                 $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datelimite, 'day'));
                 $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 3));
                 $i++;
             }
             if ($num == 0) {
                 $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoUnpaidCustomerBills"));
             }
         } else {
             $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql);
         }
     } else {
         $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed"));
     }
 }
function generateCSV()
{
    global $db, $conf;
    $TFactRef = $_REQUEST['toGenerate'];
    // Création et attribution droits fichier
    $dir = $conf->lcr->dir_output;
    $filename = 'lcr_' . date('YmdHis') . '.csv';
    $f = fopen($dir . '/' . $filename, 'w+');
    chmod($dir . '/' . $filename, 0777);
    $TTitle = array('Code client', 'Raison sociale', 'Adresse 1', 'Adresse 2', 'Code postal', 'Ville', 'Téléphone', 'Référence', 'SIREN', 'RIB', 'Agence', 'Montant', 'Monnaie', 'Accepté', 'Référence', 'Date de création', 'Date d\'échéance');
    fputcsv($f, $TTitle, ';');
    $fact = new Facture($db);
    $s = new Societe($db);
    foreach ($TFactRef as $ref_fact) {
        if ($fact->fetch('', $ref_fact) > 0 && $s->fetch($fact->socid) > 0) {
            $rib = $s->get_all_rib();
            fputcsv($f, array($s->code_client, $s->name, $s->address, '', $s->zip, $s->town, $s->phone, $ref_fact, $s->idprof1, $rib[0]->iban, '', price($fact->total_ttc), 'E', 1, $ref_fact, date('d/m/Y', $fact->date), date('d/m/Y', $fact->date_lim_reglement)), ';');
        }
    }
    fclose($f);
}
 /**
  * Delete invoice
  *
  * @param int   $id Invoice ID
  * @return type
  * 
  * @url	DELETE invoice/{id} 
  */
 function delete($id)
 {
     if (!DolibarrApiAccess::$user->rights->facture->supprimer) {
         throw new RestException(401);
     }
     $result = $this->invoice->fetch($id);
     if (!$result) {
         throw new RestException(404, 'Facture not found');
     }
     if (!DolibarrApi::_checkAccessToResource('facture', $this->facture->id)) {
         throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login);
     }
     if (!$this->invoice->delete($id)) {
         throw new RestException(500);
     }
     return array('success' => array('code' => 200, 'message' => 'Facture deleted'));
 }
 /**
  *  Show top header of page.
  *
  *  @param	PDF			$pdf     		Object PDF
  *  @param  Object		$object     	Object to show
  *  @param  int	    	$showaddress    0=no, 1=yes
  *  @param  Translate	$outputlangs	Object lang for output
  *  @return	void
  */
 function _pagehead(&$pdf, $object, $showaddress, $outputlangs)
 {
     global $conf, $langs;
     $outputlangs->load("main");
     $outputlangs->load("bills");
     $outputlangs->load("propal");
     $outputlangs->load("companies");
     $default_font_size = pdf_getPDFFontSize($outputlangs);
     pdf_pagehead($pdf, $outputlangs, $this->page_hauteur);
     // Show Draft Watermark
     if ($object->statut == 0 && !empty($conf->global->FACTURE_DRAFT_WATERMARK)) {
         pdf_watermark($pdf, $outputlangs, $this->page_hauteur, $this->page_largeur, 'mm', $conf->global->FACTURE_DRAFT_WATERMARK);
     }
     $pdf->SetTextColor(0, 0, 60);
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $w = 110;
     $posy = $this->marge_haute;
     $posx = $this->page_largeur - $this->marge_droite - $w;
     $pdf->SetXY($this->marge_gauche, $posy);
     // Logo
     $logo = $conf->mycompany->dir_output . '/logos/' . $this->emetteur->logo;
     if ($this->emetteur->logo) {
         if (is_readable($logo)) {
             $height = pdf_getHeightForLogo($logo);
             $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height);
             // width=0 (auto)
         } else {
             $pdf->SetTextColor(200, 0, 0);
             $pdf->SetFont('', 'B', $default_font_size - 2);
             $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound", $logo), 0, 'L');
             $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L');
         }
     } else {
         $text = $this->emetteur->name;
         $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L');
     }
     $pdf->SetFont('', 'B', $default_font_size + 3);
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $title = $outputlangs->transnoentities("Invoice");
     if ($object->type == 1) {
         $title = $outputlangs->transnoentities("InvoiceReplacement");
     }
     if ($object->type == 2) {
         $title = $outputlangs->transnoentities("InvoiceAvoir");
     }
     if ($object->type == 3) {
         $title = $outputlangs->transnoentities("InvoiceDeposit");
     }
     if ($object->type == 4) {
         $title = $outputlangs->transnoentities("InvoiceProFormat");
     }
     $pdf->MultiCell($w, 3, $title, '', 'R');
     $pdf->SetFont('', 'B', $default_font_size);
     $posy += 5;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($w, 4, $outputlangs->transnoentities("Ref") . " : " . $outputlangs->convToOutputCharset($object->ref), '', 'R');
     $posy += 1;
     $pdf->SetFont('', '', $default_font_size - 2);
     if ($object->ref_client) {
         $posy += 4;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("RefCustomer") . " : " . $outputlangs->convToOutputCharset($object->ref_client), '', 'R');
     }
     $objectidnext = $object->getIdReplacingInvoice('validated');
     if ($object->type == 0 && $objectidnext) {
         $objectreplacing = new Facture($this->db);
         $objectreplacing->fetch($objectidnext);
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementByInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplacing->ref), '', 'R');
     }
     if ($object->type == 1) {
         $objectreplaced = new Facture($this->db);
         $objectreplaced->fetch($object->fk_facture_source);
         $posy += 4;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ReplacementInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
     }
     if ($object->type == 2 && !empty($object->fk_facture_source)) {
         $objectreplaced = new Facture($this->db);
         $objectreplaced->fetch($object->fk_facture_source);
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CorrectionInvoice") . ' : ' . $outputlangs->convToOutputCharset($objectreplaced->ref), '', 'R');
     }
     $posy += 4;
     $pdf->SetXY($posx, $posy);
     $pdf->SetTextColor(0, 0, 60);
     $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateInvoice") . " : " . dol_print_date($object->date, "day", false, $outputlangs), '', 'R');
     if ($object->type != 2) {
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("DateEcheance") . " : " . dol_print_date($object->date_lim_reglement, "day", false, $outputlangs, true), '', 'R');
     }
     if ($object->thirdparty->code_client) {
         $posy += 3;
         $pdf->SetXY($posx, $posy);
         $pdf->SetTextColor(0, 0, 60);
         $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode") . " : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R');
     }
     $posy += 1;
     // Show list of linked objects
     $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size);
     if ($showaddress) {
         // Sender properties
         $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->client);
         // Show sender
         $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
         $posx = $this->marge_gauche;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->page_largeur - $this->marge_droite - 80;
         }
         $hautcadre = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40;
         $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82;
         // Show sender frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx, $posy - 5);
         $pdf->MultiCell(66, 5, $outputlangs->transnoentities("BillFrom") . ":", 0, 'L');
         $pdf->SetXY($posx, $posy);
         $pdf->SetFillColor(230, 230, 230);
         $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1);
         $pdf->SetTextColor(0, 0, 60);
         // Show sender name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox - 2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L');
         $posy = $pdf->getY();
         // Show sender information
         $pdf->SetXY($posx + 2, $posy);
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->MultiCell($widthrecbox - 2, 4, $carac_emetteur, 0, 'L');
         // If BILLING contact defined on invoice, we use it
         $usecontact = false;
         $arrayidcontact = $object->getIdContact('external', 'BILLING');
         if (count($arrayidcontact) > 0) {
             $usecontact = true;
             $result = $object->fetch_contact($arrayidcontact[0]);
         }
         //Recipient name
         // On peut utiliser le nom de la societe du contact
         if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) {
             $thirdparty = $object->contact;
         } else {
             $thirdparty = $object->client;
         }
         $carac_client_name = pdfBuildThirdpartyName($thirdparty, $outputlangs);
         $carac_client = pdf_build_address($outputlangs, $this->emetteur, $object->client, $usecontact ? $object->contact : '', $usecontact, 'target');
         // Show recipient
         $widthrecbox = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100;
         if ($this->page_largeur < 210) {
             $widthrecbox = 84;
         }
         // To work with US executive format
         $posy = !empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42;
         $posx = $this->page_largeur - $this->marge_droite - $widthrecbox;
         if (!empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) {
             $posx = $this->marge_gauche;
         }
         // Show recipient frame
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('', '', $default_font_size - 2);
         $pdf->SetXY($posx + 2, $posy - 5);
         $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("BillTo") . ":", 0, 'L');
         $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre);
         // Show recipient name
         $pdf->SetXY($posx + 2, $posy + 3);
         $pdf->SetFont('', 'B', $default_font_size);
         $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L');
         $posy = $pdf->getY();
         // Show recipient information
         $pdf->SetFont('', '', $default_font_size - 1);
         $pdf->SetXY($posx + 2, $posy);
         $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L');
     }
     $pdf->SetTextColor(0, 0, 0);
 }
Beispiel #6
0
// Copyright (c) 2004-2006 NBI SARL
// Author : Nicolas Bouthors <*****@*****.**>
//
// You can use and redistribute this file under the term of the GNU GPL v2.0
//
// $Id: index.php 531 2007-06-13 12:32:31Z thierry $
include "../inc/main.php";
$title = _("Client");
$roles = "manager,accounting,employee,client";
include "../top.php";
$client_role = "client";
$is_client = false;
$User = new User();
$user = $User->getInfo();
$roles = explode(",", $user->role);
$Facture = new Facture();
$total_ca_ht = 0;
$where_clause = "1";
if (isset($_GET['id_client']) and $_GET['id_client'] != "") {
    $where_clause .= " AND webfinance_invoices.id_client=" . $_GET['id_client'];
}
if (isset($_GET['mois']) and $_GET['mois'] != "") {
    $where_clause .= " AND date_format(date_facture, '%Y%m')='" . $_GET['mois'] . "'";
}
if (isset($_GET['type']) and $_GET['type'] != "") {
    switch ($_GET['type']) {
        case "unpaid":
            $where_clause .= " AND is_paye=0";
            break;
        case "paid":
            $where_clause .= " AND is_paye=1";
Beispiel #7
0
 print '<td align="center">' . $langs->trans('Date') . '</td>';
 print '<td align="right">' . $langs->trans('AmountTTC') . '</td>';
 print '<td align="right">' . $langs->trans('Received') . '</td>';
 print '<td align="right">' . $langs->trans('RemainderToPay') . '</td>';
 print '<td align="right">' . $langs->trans('PaymentAmount') . '</td>';
 print '<td align="right">&nbsp;</td>';
 print "</tr>\n";
 $var = True;
 $total = 0;
 $totalrecu = 0;
 $totalrecucreditnote = 0;
 $totalrecudeposits = 0;
 while ($i < $num) {
     $objp = $db->fetch_object($resql);
     $var = !$var;
     $invoice = new Facture($db);
     $invoice->fetch($objp->facid);
     $paiement = $invoice->getSommePaiement();
     $creditnotes = $invoice->getSumCreditNotesUsed();
     $deposits = $invoice->getSumDepositsUsed();
     $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
     $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
     print '<tr ' . $bc[$var] . '>';
     print '<td>';
     print $invoice->getNomUrl(1, '');
     print "</td>\n";
     // Date
     print '<td align="center">' . dol_print_date($db->jdate($objp->df), 'day') . "</td>\n";
     // Prix
     print '<td align="right">' . price($objp->total_ttc) . '</td>';
     // Recu
Beispiel #8
0
$result = $db->query($sql);
if ($result) {
    $num = $db->num_rows($result);
    $i = 0;
    while ($i < $num) {
        $row = $db->fetch_row($result);
        $cgs[$row[0]] = $row[1] . ' ' . $row[2];
        $i++;
    }
}
/*
 * Cr�ation
 *
 */
$form = new Form($db);
$facture_static = new Facture($db);
if ($_GET["id"]) {
    $sql = "SELECT f.facnumber, f.rowid as facid, l.fk_product, l.description, l.price,";
    $sql .= " l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,";
    $sql .= " l.date_start as date_start, l.date_end as date_end,";
    $sql .= " l.fk_code_ventilation ";
    $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as l";
    $sql .= " , " . MAIN_DB_PREFIX . "facture as f";
    $sql .= " WHERE f.rowid = l.fk_facture AND f.fk_statut = 1 AND l.rowid = " . $_GET["id"];
    $result = $db->query($sql);
    if ($result) {
        $num_lignes = $db->num_rows($result);
        $i = 0;
        if ($num_lignes) {
            $objp = $db->fetch_object($result);
            if ($objp->fk_code_ventilation == 0) {
Beispiel #9
0
	/**
	 *      \brief      Charge les donnees en memoire pour affichage ulterieur
	 *      \param      $max        Nombre maximum d'enregistrements a charger
	 */
	function loadBox($max=5)
	{
		global $conf, $user, $langs, $db;

		$this->max=$max;

		include_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
		$facturestatic=new Facture($db);

		$text = $langs->trans("BoxTitleLastCustomerBills",$max);
		$this->info_box_head = array(
				'text' => $text,
				'limit'=> dol_strlen($text)
		);

		if ($user->rights->facture->lire)
		{
			$sql = "SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.datef as df";
			$sql.= ", f.paye, f.fk_statut, f.datec, f.tms";
			$sql.= ", s.nom, s.rowid as socid";
			$sql.= ", f.date_lim_reglement as datelimite";
			$sql.= " FROM (".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
			$sql.= ")";
			$sql.= " WHERE f.fk_soc = s.rowid";
			$sql.= " AND s.entity = ".$conf->entity;
			if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = "******" AND s.rowid = ".$user->societe_id;
			$sql.= " ORDER BY f.tms DESC";
			$sql.= $db->plimit($max, 0);

			$result = $db->query($sql);
			if ($result)
			{
				$num = $db->num_rows($result);
				$now=gmmktime();

				$i = 0;
				$l_due_date = $langs->trans('Late').' ('.strtolower($langs->trans('DateEcheance')).': %s)';

				while ($i < $num)
				{
					$objp = $db->fetch_object($result);
					$datelimite=$db->jdate($objp->datelimite);
					$datec=$db->jdate($objp->datec);

					$picto='bill';
					if ($objp->type == 1) $picto.='r';
					if ($objp->type == 2) $picto.='a';
					$late = '';
					if ($objp->paye == 0 && ($objp->fk_statut != 2 && $objp->fk_statut != 3) && $datelimite < ($now - $conf->facture->client->warning_delay)) { $late = img_warning(sprintf($l_due_date,dol_print_date($datelimite,'day')));}

					$this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"',
                    'logo' => $picto,
                    'url' => DOL_URL_ROOT."/compta/facture.php?facid=".$objp->facid);

					$this->info_box_contents[$i][1] = array('td' => 'align="left"',
                    'text' => $objp->facnumber,
                    'text2'=> $late,
                    'url' => DOL_URL_ROOT."/compta/facture.php?facid=".$objp->facid);

					$this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"',
                    'logo' => 'company',
                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);

					$this->info_box_contents[$i][3] = array('td' => 'align="left"',
                    'text' => $objp->nom,
                    'maxlength'=>40,
                    'url' => DOL_URL_ROOT."/comm/fiche.php?socid=".$objp->socid);

					$this->info_box_contents[$i][4] = array('td' => 'align="right"',
                    'text' => dol_print_date($datec,'day'),
					);

					$this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"',
                    'text' => $facturestatic->LibStatut($objp->paye,$objp->fk_statut,3));

					$i++;
				}

				if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedInvoices"));
			}
			else
			{
				$this->info_box_contents[0][0] = array(	'td' => 'align="left"',
    	        										'maxlength'=>500,
	            										'text' => ($db->error().' sql='.$sql));
			}

		}
		else {
			$this->info_box_contents[0][0] = array('td' => 'align="left"',
            'text' => $langs->trans("ReadPermissionNotAllowed"));
		}
	}
Beispiel #10
0
 public function recup_historique()
 {
     $requete = $this->_db->prepare('select * from facture where idutil=:idutil and valider=:valider');
     $requete->execute(array(':idutil' => $_SESSION['id'], ':valider' => 1));
     $results = $requete->fetchAll();
     $tabobject = array();
     if (empty($results)) {
         return false;
     }
     foreach ($results as $result) {
         $mafacture = new Facture();
         $mafacture->setId($result['id'])->setIdutil($result['idutil'])->setDate($result['date'])->setValider($result['valider']);
         array_push($tabobject, $mafacture);
         // Push l'objet $article dans le tableau $tabobject
     }
     return $tabobject;
 }
Beispiel #11
0
 /**
  * 	Create a predefined invoice
  *
  * 	@param		User	$user		User object
  * 	@param		int		$facid		Id of source invoice
  *	@return		int					<0 if KO, id of invoice if OK
  */
 function create($user, $facid)
 {
     global $conf, $langs;
     $error = 0;
     $now = dol_now();
     // Clean parameters
     $this->titre = trim($this->titre);
     // Validate parameters
     if (empty($this->titre)) {
         $this->error = $langs->trans("ErrorFieldRequired", $langs->trans("Title"));
         return -3;
     }
     $this->db->begin();
     // Charge facture modele
     $facsrc = new Facture($this->db);
     $result = $facsrc->fetch($facid);
     if ($result > 0) {
         // On positionne en mode brouillon la facture
         $this->brouillon = 1;
         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "facture_rec (";
         $sql .= "titre";
         $sql .= ", fk_soc";
         $sql .= ", entity";
         $sql .= ", datec";
         $sql .= ", amount";
         $sql .= ", remise";
         $sql .= ", note";
         $sql .= ", fk_user_author";
         $sql .= ", fk_projet";
         $sql .= ", fk_cond_reglement";
         $sql .= ", fk_mode_reglement";
         $sql .= ") VALUES (";
         $sql .= "'" . $this->titre . "'";
         $sql .= ", '" . $facsrc->socid . "'";
         $sql .= ", " . $conf->entity;
         $sql .= ", " . $this->db->idate($now);
         $sql .= ", '" . $facsrc->amount . "'";
         $sql .= ", '" . $facsrc->remise . "'";
         $sql .= ", '" . $this->db->escape($this->note) . "'";
         $sql .= ", '" . $user->id . "'";
         $sql .= ", " . ($facsrc->fk_project ? "'" . $facsrc->fk_project . "'" : "null");
         $sql .= ", '" . $facsrc->cond_reglement_id . "'";
         $sql .= ", '" . $facsrc->mode_reglement_id . "'";
         $sql .= ")";
         if ($this->db->query($sql)) {
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "facture_rec");
             /*
              * Lines
              */
             $num = count($facsrc->lines);
             for ($i = 0; $i < $num; $i++) {
                 $result_insert = $this->addline($this->id, $facsrc->lines[$i]->desc, $facsrc->lines[$i]->subprice, $facsrc->lines[$i]->qty, $facsrc->lines[$i]->tva_tx, $facsrc->lines[$i]->fk_product, $facsrc->lines[$i]->remise_percent, 'HT', 0, '', 0, $facsrc->lines[$i]->product_type, $facsrc->lines[$i]->rang, $facsrc->lines[$i]->special_code);
                 if ($result_insert < 0) {
                     $error++;
                 }
             }
             if ($error) {
                 $this->db->rollback();
             } else {
                 $this->db->commit();
                 return $this->id;
             }
         } else {
             $this->error = $this->db->error() . ' sql=' . $sql;
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->db->rollback();
         return -1;
     }
 }
Beispiel #12
0
    $result = $bprev->create($conf->global->PRELEVEMENT_CODE_BANQUE, $conf->global->PRELEVEMENT_CODE_GUICHET);
    if ($result < 0) {
        $mesg = '<div class="error">' . $bprev->error . '</div>';
    }
    if ($result == 0) {
        $mesg = '<div class="error">' . $langs->trans("NoInvoiceCouldBeWithdrawed") . '</div>';
        foreach ($bprev->invoice_in_error as $key => $val) {
            $mesg .= $val . "<br>\n";
        }
    }
}
/*
 * View
 */
$thirdpartystatic = new Societe($db);
$invoicestatic = new Facture($db);
$bprev = new BonPrelevement($db);
llxHeader('', $langs->trans("NewStandingOrder"));
if (prelevement_check_config() < 0) {
    $langs->load("errors");
    print '<div class="error">';
    print $langs->trans("ErrorModuleSetupNotComplete");
    print '</div>';
}
/*$h=0;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php';
$head[$h][1] = $langs->trans("NewStandingOrder");
$head[$h][2] = 'payment';
$hselected = 'payment';
$h++;
Beispiel #13
0
         } else {
             $error++;
             $errmsg = $acct->error;
             $errmsgs = $acct->errors;
         }
     } else {
         $error++;
         $errmsg = $acct->error;
         $errmsgs = $acct->errors;
     }
 }
 // If option choosed, we create invoice
 if ($option == 'bankviainvoice' && $accountid || $option == 'invoiceonly') {
     require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
     require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/paymentterm.class.php';
     $invoice = new Facture($db);
     $customer = new Societe($db);
     if (!$error) {
         if (!($object->fk_soc > 0)) {
             $langs->load("errors");
             $errmsg = $langs->trans("ErrorMemberNotLinkedToAThirpartyLinkOrCreateFirst");
             $error++;
         }
     }
     if (!$error) {
         $result = $customer->fetch($object->fk_soc);
         if ($result <= 0) {
             $errmsg = $customer->error;
             $errmsgs = $acct->errors;
             $error++;
         }
Beispiel #14
0
must_login();
if (!isset($_GET['id_client']) or !isset($_GET['id_invoice'])) {
    echo "Missing arguments";
    exit;
}
if (!is_numeric($_GET['id_client']) or !is_numeric($_GET['id_invoice'])) {
    echo "Wrong arguments";
    exit;
}
$Client = new Client();
# check client and invoice
if (!$Client->exists($_GET['id_client'])) {
    echo _("This client doesn't exist");
    exit;
}
$Invoice = new Facture();
if ($Invoice->exists($_GET['id_invoice'])) {
    $inv = $Invoice->getInfos($_GET['id_invoice']);
    if ($inv->id_client != $_GET['id_client']) {
        echo _("This invoice isn't yours!");
        exit;
    }
    $Client = new Client($_GET['id_client']);
}
#site
$result = mysql_query("SELECT value FROM webfinance_pref WHERE type_pref='societe' AND owner=-1") or wf_mysqldie();
list($value) = mysql_fetch_array($result);
mysql_free_result($result);
$company = unserialize(base64_decode($value));
$site = "webfinance.dev.jexiste.org";
if (!empty($company->wf_url) and strlen($company->wf_url) > 3) {
Beispiel #15
0
 /**
  * Tag invoice as validated + call trigger BILL_VALIDATE
  * Object must have lines loaded with fetch_lines
  *
  * @param	User	$user           Object user that validate
  * @param   string	$force_number	Reference to force on invoice
  * @param	int		$idwarehouse	Id of warehouse to use for stock decrease
  * @return	int						<0 if KO, >0 if OK
  */
 function validate($user, $force_number = '', $idwarehouse = 0)
 {
     global $conf, $langs;
     require_once DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php";
     $now = dol_now();
     $error = 0;
     dol_syslog(get_class($this) . '::validate user='******', force_number=' . $force_number . ', idwarehouse=' . $idwarehouse, LOG_WARNING);
     // Check parameters
     if (!$this->brouillon) {
         dol_syslog(get_class($this) . "::validate no draft status", LOG_WARNING);
         return 0;
     }
     if (!$user->rights->facture->valider) {
         $this->error = 'Permission denied';
         dol_syslog(get_class($this) . "::validate " . $this->error, LOG_ERR);
         return -1;
     }
     $this->db->begin();
     $this->fetch_thirdparty();
     $this->fetch_lines();
     // Check parameters
     if ($this->type == 1) {
         // Controle que facture source connue
         if ($this->fk_facture_source <= 0) {
             $this->error = $langs->trans("ErrorFieldRequired", $langs->trans("InvoiceReplacement"));
             $this->db->rollback();
             return -10;
         }
         // Charge la facture source a remplacer
         $facreplaced = new Facture($this->db);
         $result = $facreplaced->fetch($this->fk_facture_source);
         if ($result <= 0) {
             $this->error = $langs->trans("ErrorBadInvoice");
             $this->db->rollback();
             return -11;
         }
         // Controle que facture source non deja remplacee par une autre
         $idreplacement = $facreplaced->getIdReplacingInvoice('validated');
         if ($idreplacement && $idreplacement != $this->id) {
             $facreplacement = new Facture($this->db);
             $facreplacement->fetch($idreplacement);
             $this->error = $langs->trans("ErrorInvoiceAlreadyReplaced", $facreplaced->ref, $facreplacement->ref);
             $this->db->rollback();
             return -12;
         }
         $result = $facreplaced->set_canceled($user, 'replaced', '');
         if ($result < 0) {
             $this->error = $facreplaced->error;
             $this->db->rollback();
             return -13;
         }
     }
     // Define new ref
     if ($force_number) {
         $num = $force_number;
     } else {
         if (preg_match('/^[\\(]?PROV/i', $this->ref)) {
             if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
                 $this->date = dol_now();
                 $this->date_lim_reglement = $this->calculate_date_lim_reglement();
             }
             $num = $this->getNextNumRef($this->client);
         } else {
             $num = $this->ref;
         }
     }
     if ($num) {
         $this->update_price(1);
         // Validate
         $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture';
         $sql .= " SET facnumber='" . $num . "', fk_statut = 1, fk_user_valid = " . $user->id . ", date_valid = '" . $this->db->idate($now) . "'";
         if (!empty($conf->global->FAC_FORCE_DATE_VALIDATION)) {
             $sql .= ', datef=' . $this->db->idate($this->date);
             $sql .= ', date_lim_reglement=' . $this->db->idate($this->date_lim_reglement);
         }
         $sql .= ' WHERE rowid = ' . $this->id;
         dol_syslog(get_class($this) . "::validate sql=" . $sql);
         $resql = $this->db->query($sql);
         if (!$resql) {
             dol_syslog(get_class($this) . "::validate Echec update - 10 - sql=" . $sql, LOG_ERR);
             dol_print_error($this->db);
             $error++;
         }
         // On verifie si la facture etait une provisoire
         if (!$error && preg_match('/^[\\(]?PROV/i', $this->ref)) {
             // La verif qu'une remise n'est pas utilisee 2 fois est faite au moment de l'insertion de ligne
         }
         if (!$error) {
             // Define third party as a customer
             $result = $this->client->set_as_client();
             // Si active on decremente le produit principal et ses composants a la validation de facture
             if ($this->type != 3 && $result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL) {
                 require_once DOL_DOCUMENT_ROOT . "/product/stock/class/mouvementstock.class.php";
                 $langs->load("agenda");
                 // Loop on each line
                 $cpt = count($this->lines);
                 for ($i = 0; $i < $cpt; $i++) {
                     if ($this->lines[$i]->fk_product > 0) {
                         $mouvP = new MouvementStock($this->db);
                         // We decrease stock for product
                         if ($this->type == 2) {
                             $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr", $num));
                         } else {
                             $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr", $num));
                         }
                         if ($result < 0) {
                             $error++;
                         }
                     }
                 }
             }
         }
         if (!$error) {
             $this->oldref = '';
             // Rename directory if dir was a temporary ref
             if (preg_match('/^[\\(]?PROV/i', $this->ref)) {
                 // On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref)
                 // afin de ne pas perdre les fichiers attaches
                 $facref = dol_sanitizeFileName($this->ref);
                 $snumfa = dol_sanitizeFileName($num);
                 $dirsource = $conf->facture->dir_output . '/' . $facref;
                 $dirdest = $conf->facture->dir_output . '/' . $snumfa;
                 if (file_exists($dirsource)) {
                     dol_syslog(get_class($this) . "::validate rename dir " . $dirsource . " into " . $dirdest);
                     if (@rename($dirsource, $dirdest)) {
                         $this->oldref = $facref;
                         dol_syslog("Rename ok");
                         // Suppression ancien fichier PDF dans nouveau rep
                         dol_delete_file($conf->facture->dir_output . '/' . $snumfa . '/' . $facref . '.*');
                     }
                 }
             }
         }
         // Set new ref and define current statut
         if (!$error) {
             $this->ref = $num;
             $this->facnumber = $num;
             $this->statut = 1;
             $this->date_validation = $now;
         }
         // Trigger calls
         if (!$error) {
             // Appel des triggers
             include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
             $interface = new Interfaces($this->db);
             $result = $interface->run_triggers('BILL_VALIDATE', $this, $user, $langs, $conf);
             if ($result < 0) {
                 $error++;
                 $this->errors = $interface->errors;
             }
             // Fin appel triggers
         }
     } else {
         $error++;
     }
     if (!$error) {
         $this->db->commit();
         return 1;
     } else {
         $this->db->rollback();
         $this->error = $this->db->lasterror();
         return -1;
     }
 }
Beispiel #16
0
if (isset($_GET["account"]) || isset($_GET["ref"])) {
    $id = isset($_GET["account"]) ? $_GET["account"] : (isset($_GET["ref"]) ? $_GET["ref"] : '');
}
$fieldid = isset($_GET["ref"]) ? 'ref' : 'rowid';
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'banque', $id, 'bank_account&bank_account', '', '', $fieldid);
$vline = isset($_GET["vline"]) ? $_GET["vline"] : $_POST["vline"];
$page = isset($_GET["page"]) ? $_GET["page"] : 0;
/*
 * View
 */
llxHeader();
$societestatic = new Societe($db);
$facturestatic = new Facture($db);
$facturefournstatic = new FactureFournisseur($db);
$socialcontribstatic = new ChargeSociales($db);
$form = new Form($db);
if ($_REQUEST["account"] || $_REQUEST["ref"]) {
    if ($vline) {
        $viewline = $vline;
    } else {
        $viewline = 20;
    }
    $acct = new Account($db);
    if ($_GET["account"]) {
        $result = $acct->fetch($_GET["account"]);
    }
    if ($_GET["ref"]) {
        $result = $acct->fetch(0, $_GET["ref"]);
Beispiel #17
0
 print '</td><td class="liste_titre" colspan="3" align="right">';
 print '<input type="image" class="liste_titre" name="button_search" src="' . DOL_URL_ROOT . '/theme/' . $conf->theme . '/img/search.png" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
 print '</td>';
 print '<td class="liste_titre" align="center">';
 if ($conf->use_javascript_ajax) {
     print '<a href="#" id="checkall">' . $langs->trans("All") . '</a> / <a href="#" id="checknone">' . $langs->trans("None") . '</a>';
 }
 print '</td>';
 print "</tr>\n";
 print '</form>';
 if ($num > 0) {
     $var = True;
     $total_ht = 0;
     $total_ttc = 0;
     $total_paid = 0;
     $facturestatic = new Facture($db);
     print '<form id="form_generate_pdf" method="POST" action="' . $_SERVER["PHP_SELF"] . '?sortfield=' . $sortfield . '&sortorder=' . $sortorder . '">';
     print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     while ($i < $num) {
         $objp = $db->fetch_object($resql);
         $date_limit = $db->jdate($objp->datelimite);
         $var = !$var;
         print "<tr {$bc[$var]}>";
         $classname = "impayee";
         print '<td nowrap="nowrap">';
         $facturestatic->id = $objp->facid;
         $facturestatic->ref = $objp->facnumber;
         $facturestatic->type = $objp->type;
         print '<table class="nobordernopadding"><tr class="nocellnopadd">';
         // Ref
         print '<td width="100" class="nobordernopadding" nowrap="nowrap">';
Beispiel #18
0
 }
 // If mode_reglement_id not found
 if (empty($cond_reglement_id)) {
     $cond_reglement_id = 0;
 }
 // If cond_reglement_id not found
 $note .= $_POST['txtaNotes'];
 dol_syslog("obj_facturation->getSetPaymentMode()=" . $obj_facturation->getSetPaymentMode() . " mode_reglement_id=" . $mode_reglement_id . " cond_reglement_id=" . $cond_reglement_id);
 $error = 0;
 $db->begin();
 $user->fetch($_SESSION['uid']);
 $user->getrights();
 $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY'];
 $societe = new Societe($db);
 $societe->fetch($thirdpartyid);
 $invoice = new Facture($db);
 // Get content of cart
 $tab_liste = $_SESSION['poscart'];
 // Loop on each product
 $tab_liste_size = count($tab_liste);
 for ($i = 0; $i < $tab_liste_size; $i++) {
     // Recuperation de l'article
     $product = new Product($db);
     $product->fetch($tab_liste[$i]['fk_article']);
     $ret = array('label' => $product->label, 'tva_tx' => $product->tva_tx, 'price' => $product->price);
     if ($conf->global->PRODUIT_MULTIPRICES) {
         if (isset($product->multiprices[$societe->price_level])) {
             $ret['price'] = $product->multiprices[$societe->price_level];
         }
     }
     $tab_article = $ret;
Beispiel #19
0
             print '<td align="right">' . $fichinter_static->getLibStatut(3) . '</td>' . "\n";
             print '</tr>';
             $var = !$var;
             $i++;
         }
         $db->free($resql);
     } else {
         dol_print_error($db);
     }
     print "</table>";
 }
 /*
  *   Last invoices
  */
 if ($conf->facture->enabled && $user->rights->facture->lire) {
     $facturestatic = new Facture($db);
     print '<table class="noborder" width="100%">';
     $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
     $sql .= ' f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut,';
     $sql .= ' s.nom, s.rowid as socid,';
     $sql .= ' SUM(pf.amount) as am';
     $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s," . MAIN_DB_PREFIX . "facture as f";
     $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'paiement_facture as pf ON f.rowid=pf.fk_facture';
     $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = " . $objsoc->id;
     $sql .= ' GROUP BY f.rowid, f.facnumber, f.type, f.amount, f.total, f.total_ttc,';
     $sql .= ' f.datef, f.datec, f.paye, f.fk_statut,';
     $sql .= ' s.nom, s.rowid';
     $sql .= " ORDER BY f.datef DESC, f.datec DESC";
     $resql = $db->query($sql);
     if ($resql) {
         $var = true;
Beispiel #20
0
	print ' ('.$langs->trans("ToComplete").')';
	$email=$order->client->email;
	$email=(GETPOST("email")?GETPOST("email"):(isValidEmail($email)?$email:''));
	print '</td><td class="CTableRow'.($var?'1':'2').'"><input class="flat" type="text" name="email" size="48" value="'.$email.'"></td></tr>'."\n";
}


// Payment on customer invoice
if (GETPOST("source") == 'invoice')
{
	$found=true;
	$langs->load("bills");

	require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");

	$invoice=new Facture($db);
	$result=$invoice->fetch('',$_REQUEST["ref"]);
	if ($result < 0)
	{
		$mesg=$invoice->error;
		$error++;
	}
	else
	{
		$result=$invoice->fetch_thirdparty($invoice->socid);
	}

	$amount=$invoice->total_ttc - $invoice->getSommePaiement();
    if (GETPOST("amount",'int')) $amount=GETPOST("amount",'int');
    $amount=price2num($amount);
    /**
     * testFactureCreate
     *
     * @return int
     */
    public function testFactureMercure()
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

		require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php';
		require_once dirname(__FILE__).'/../../htdocs/core/modules/facture/mod_facture_mercure.php';

		//$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@3}';
		//$conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@3}';
		$conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}-{0000@1}';
		$conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}-{0000@1}';

		$localobject=new Facture($this->savdb);
		$localobject->initAsSpecimen();
		$localobject->date=dol_mktime(0, 0, 0, 1, 1, 2012);
		$numbering=new mod_facture_mercure();
		$result=$numbering->getNextValue($mysoc, $localobject);
		print __METHOD__." result=".$result."\n";

		$localobject=new Facture($this->savdb);
		$localobject->initAsSpecimen();
		$localobject->date=dol_mktime(0, 0, 0, 1, 1, 2011);
		$numbering=new mod_facture_mercure();
		$result=$numbering->getNextValue($mysoc, $localobject);
    	print __METHOD__." result=".$result."\n";

    	$this->assertLessThan($result, 0);
    	return $result;
    }
Beispiel #22
0
 /**
  * Returns an array containing the previous situations as Facture objects
  *
  * @return mixed -1 if error, array of previous situations
  */
 function get_prev_sits()
 {
     $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture';
     $sql .= ' where situation_cycle_ref = ' . $this->situation_cycle_ref;
     $sql .= ' and situation_counter < ' . $this->situation_counter;
     $resql = $this->db->query($sql);
     $res = array();
     if ($resql && $resql->num_rows > 0) {
         while ($row = $this->db->fetch_object($resql)) {
             $id = $row->rowid;
             $situation = new Facture($this->db);
             $situation->fetch($id);
             $res[] = $situation;
         }
     } else {
         $this->error = $this->db->error();
         dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR);
         return -1;
     }
     return $res;
 }
Beispiel #23
0
     print $langs->trans('AlreadyPaid');
 }
 print ' :</td><td align="right">' . price($totalpaye) . '</td><td>&nbsp;</td></tr>';
 $resteapayeraffiche = $resteapayer;
 // Loop on each credit note or deposit amount applied
 $creditnoteamount = 0;
 $depositamount = 0;
 $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
 $sql .= " re.description, re.fk_facture_source";
 $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re";
 $sql .= " WHERE fk_facture = " . $object->id;
 $resql = $db->query($sql);
 if ($resql) {
     $num = $db->num_rows($resql);
     $i = 0;
     $invoice = new Facture($db);
     while ($i < $num) {
         $obj = $db->fetch_object($resql);
         $invoice->fetch($obj->fk_facture_source);
         print '<tr><td colspan="' . $nbcols . '" align="right">';
         if ($invoice->type == Facture::TYPE_CREDIT_NOTE) {
             print $langs->trans("CreditNote") . ' ';
         }
         if ($invoice->type == Facture::TYPE_DEPOSIT) {
             print $langs->trans("Deposit") . ' ';
         }
         print $invoice->getNomUrl(0);
         print ' :</td>';
         print '<td align="right">' . price($obj->amount_ttc) . '</td>';
         print '<td align="right">';
         print '<a href="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '&action=unlinkdiscount&discountid=' . $obj->rowid . '">' . img_delete() . '</a>';
Beispiel #24
0
 /**
  *      Add a record into bank for payment with links between this bank record and invoices of payment.
  *      All payment properties (this->amount, this->amounts, ...) must have been set first like after a call to create().
  *
  *      @param	User	$user               Object of user making payment
  *      @param  string	$mode               'payment', 'payment_supplier'
  *      @param  string	$label              Label to use in bank record
  *      @param  int		$accountid          Id of bank account to do link with
  *      @param  string	$emetteur_nom       Name of transmitter
  *      @param  string	$emetteur_banque    Name of bank
  *      @param	int		$notrigger			No trigger
  *      @return int                 		<0 if KO, bank_line_id if OK
  */
 function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0)
 {
     global $conf, $langs, $user;
     $error = 0;
     $bank_line_id = 0;
     if (!empty($conf->banque->enabled)) {
         if ($accountid <= 0) {
             $this->error = 'Bad value for parameter accountid';
             dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->error, LOG_ERR);
             return -1;
         }
         $this->db->begin();
         $this->fk_account = $accountid;
         require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
         dol_syslog("{$user->id},{$mode},{$label},{$this->fk_account},{$emetteur_nom},{$emetteur_banque}");
         $acc = new Account($this->db);
         $result = $acc->fetch($this->fk_account);
         $totalamount = $this->amount;
         if (empty($totalamount)) {
             $totalamount = $this->total;
         }
         // For backward compatibility
         if ($mode == 'payment_supplier') {
             $totalamount = -$totalamount;
         }
         // Insert payment into llx_bank
         $bank_line_id = $acc->addline($this->datepaye, $this->paiementid, $label, $totalamount, $this->num_paiement, '', $user, $emetteur_nom, $emetteur_banque);
         // Mise a jour fk_bank dans llx_paiement
         // On connait ainsi le paiement qui a genere l'ecriture bancaire
         if ($bank_line_id > 0) {
             $result = $this->update_fk_bank($bank_line_id);
             if ($result <= 0) {
                 $error++;
                 dol_print_error($this->db);
             }
             // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
             if (!$error) {
                 $url = '';
                 if ($mode == 'payment') {
                     $url = DOL_URL_ROOT . '/compta/paiement/card.php?id=';
                 }
                 if ($mode == 'payment_supplier') {
                     $url = DOL_URL_ROOT . '/fourn/paiement/card.php?id=';
                 }
                 if ($url) {
                     $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
                     if ($result <= 0) {
                         $error++;
                         dol_print_error($this->db);
                     }
                 }
             }
             // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
             if (!$error && $label != '(WithdrawalPayment)') {
                 $linkaddedforthirdparty = array();
                 foreach ($this->amounts as $key => $value) {
                     if ($mode == 'payment') {
                         $fac = new Facture($this->db);
                         $fac->fetch($key);
                         $fac->fetch_thirdparty();
                         if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) {
                             $result = $acc->add_url_line($bank_line_id, $fac->thirdparty->id, DOL_URL_ROOT . '/comm/card.php?socid=', $fac->thirdparty->name, 'company');
                             if ($result <= 0) {
                                 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->db->lasterror());
                             }
                             $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id;
                             // Mark as done for this thirdparty
                         }
                     }
                     if ($mode == 'payment_supplier') {
                         $fac = new FactureFournisseur($this->db);
                         $fac->fetch($key);
                         $fac->fetch_thirdparty();
                         if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) {
                             $result = $acc->add_url_line($bank_line_id, $fac->thirdparty->id, DOL_URL_ROOT . '/fourn/card.php?socid=', $fac->thirdparty->name, 'company');
                             if ($result <= 0) {
                                 dol_syslog(get_class($this) . '::addPaymentToBank ' . $this->db->lasterror());
                             }
                             $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id;
                             // Mark as done for this thirdparty
                         }
                     }
                 }
             }
             if (!$error && !$notrigger) {
                 // Appel des triggers
                 $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
                 if ($result < 0) {
                     $error++;
                 }
                 // Fin appel triggers
             }
         } else {
             $this->error = $acc->error;
             $error++;
         }
         if (!$error) {
             $this->db->commit();
         } else {
             $this->db->rollback();
         }
     }
     if (!$error) {
         return $bank_line_id;
     } else {
         return -1;
     }
 }
$action = GETPOST('action', 'alpha');
$bid = GETPOST('bid', 'int');
// Security check
$socid = '';
if ($user->societe_id > 0) {
    $action = '';
    $socid = $user->societe_id;
}
/*
 * Actions
 */
/*
 * View
 */
$now = dol_now();
$facturestatic = new Facture($db);
$facturesupplierstatic = new FactureFournisseur($db);
$form = new Form($db);
$formfile = new FormFile($db);
$thirdpartystatic = new Societe($db);
llxHeader("", $langs->trans("AccountancyTreasuryArea"));
print_fiche_titre($langs->trans("AccountancyTreasuryArea"));
print '<div class="fichecenter"><div class="fichethirdleft">';
$max = 3;
/*
 * Search invoices
 */
if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
    print '<form method="post" action="' . DOL_URL_ROOT . '/compta/facture/list.php">';
    print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
    print '<table class="noborder nohover" width="100%">';
Beispiel #26
0
        print '<input type="hidden" name="shipToCountryCode" value="' . $shipToCountryCode . '">' . "\n";
        print '<input type="hidden" name="shipToZip" value="' . $shipToZip . '">' . "\n";
        print '<input type="hidden" name="shipToStreet2" value="' . $shipToStreet2 . '">' . "\n";
        print '<input type="hidden" name="phoneNum" value="' . $phoneNum . '">' . "\n";
    } else {
        print '<!-- Shipping address not complete, so we don t use it -->' . "\n";
    }
    print '<input type="hidden" name="email" value="' . $order->thirdparty->email . '">' . "\n";
    print '<input type="hidden" name="desc" value="' . $langs->trans("Order") . ' ' . $order->ref . '">' . "\n";
}
// Payment on customer invoice
if (GETPOST("source") == 'invoice' && $valid) {
    $found = true;
    $langs->load("bills");
    require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
    $invoice = new Facture($db);
    $result = $invoice->fetch('', $ref);
    if ($result < 0) {
        $mesg = $invoice->error;
        $error++;
    } else {
        $result = $invoice->fetch_thirdparty($invoice->socid);
    }
    $amount = price2num($invoice->total_ttc - $invoice->getSommePaiement());
    if (GETPOST("amount", 'int')) {
        $amount = GETPOST("amount", 'int');
    }
    $amount = price2num($amount);
    $fulltag = 'INV=' . $invoice->ref . '.CUS=' . $invoice->thirdparty->id;
    //$fulltag.='.NAM='.strtr($invoice->thirdparty->name,"-"," ");
    if (!empty($TAG)) {
/**
 *  Create a document onto disk according to template module.
 *
 *	@param	DoliDB		$db  			Database handler
 *	@param  Facture		$object			Object invoice
 *	@param	string		$modele			Force template to use ('' to not force)
 *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
 *  @param  int			$hidedetails    Hide details of lines
 *  @param  int			$hidedesc       Hide description
 *  @param  int			$hideref        Hide ref
 *	@return int        					<0 if KO, >0 if OK
 * @deprecated Use the new function generateDocument of Facture class
 * @see Facture::generateDocument()
 */
function facture_pdf_create(DoliDB $db, Facture $object, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
    dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING);
    return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}
/*
 * Main
 */
@set_time_limit(0);
print "***** " . $script_file . " (" . $version . ") pid=" . dol_getmypid() . " *****\n";
dol_syslog($script_file . " launched with arg " . join(',', $argv));
if (!isset($argv[3]) || !$argv[3]) {
    print "Usage: " . $script_file . " bank_ref [bank_receipt_number|all] (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
    exit(-1);
}
$bankref = $argv[1];
$num = $argv[2];
$model = $argv[3];
$newlangid = 'en_EN';
// To force a new lang id
$invoicestatic = new Facture($db);
$invoicesupplierstatic = new FactureFournisseur($db);
$societestatic = new Societe($db);
$chargestatic = new ChargeSociales($db);
$memberstatic = new Adherent($db);
$paymentstatic = new Paiement($db);
$paymentsupplierstatic = new PaiementFourn($db);
$paymentsocialcontributionstatic = new PaymentSocialContribution($db);
$paymentvatstatic = new Tva($db);
$bankstatic = new Account($db);
$banklinestatic = new AccountLine($db);
// Parse parameters
foreach ($argv as $key => $value) {
    $found = false;
    // Define options
    if (preg_match('/^lang=/i', $value)) {
Beispiel #29
0
}
$result = restrictedArea($user, 'tax', '', '', 'charges');
/*
 * View
 */
$morequerystring = '';
$listofparams = array('date_startmonth', 'date_startyear', 'date_startday', 'date_endmonth', 'date_endyear', 'date_endday');
foreach ($listofparams as $param) {
    if (GETPOST($param) != '') {
        $morequerystring .= ($morequerystring ? '&' : '') . $param . '=' . GETPOST($param);
    }
}
llxHeader('', '', '', '', 0, 0, '', '', $morequerystring);
$form = new Form($db);
$company_static = new Societe($db);
$invoice_customer = new Facture($db);
$invoice_supplier = new FactureFournisseur($db);
$product_static = new Product($db);
$payment_static = new Paiement($db);
$paymentfourn_static = new PaiementFourn($db);
//print load_fiche_titre($langs->trans("VAT"),"");
//$fsearch.='<br>';
$fsearch .= '  <input type="hidden" name="year" value="' . $year . '">';
$fsearch .= '  <input type="hidden" name="modetax" value="' . $modetax . '">';
//$fsearch.='  '.$langs->trans("SalesTurnoverMinimum").': ';
//$fsearch.='  <input type="text" name="min" value="'.$min.'">';
// Affiche en-tete du rapport
if ($modetax == 1) {
    $nom = $langs->trans("VATReportByQuartersInDueDebtMode");
    $calcmode = $langs->trans("CalcModeVATDebt");
    $calcmode .= '<br>(' . $langs->trans("TaxModuleSetupToModifyRules", DOL_URL_ROOT . '/admin/taxes.php') . ')';
Beispiel #30
0
 print '<br><table class="noborder" width="100%">';
 print '<tr class="liste_titre">';
 print '<td>' . $langs->trans('Bill') . '</td>';
 print '<td>' . $langs->trans('Company') . '</td>';
 print '<td align="right">' . $langs->trans('ExpectedToPay') . '</td>';
 print '<td align="right">' . $langs->trans('PayedByThisPayment') . '</td>';
 print '<td align="right">' . $langs->trans('RemainderToPay') . '</td>';
 print '<td align="right">' . $langs->trans('Status') . '</td>';
 print "</tr>\n";
 if ($num > 0) {
     $var = True;
     while ($i < $num) {
         $objp = $db->fetch_object($resql);
         $var = !$var;
         print '<tr ' . $bc[$var] . '>';
         $invoice = new Facture($db);
         $invoice->fetch($objp->facid);
         $paiement = $invoice->getSommePaiement();
         $creditnotes = $invoice->getSumCreditNotesUsed();
         $deposits = $invoice->getSumDepositsUsed();
         $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
         $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
         // Invoice
         print '<td>';
         print $invoice->getNomUrl(1);
         print "</td>\n";
         // Third party
         print '<td>';
         $thirdpartystatic->id = $objp->socid;
         $thirdpartystatic->name = $objp->name;
         print $thirdpartystatic->getNomUrl(1);