示例#1
0
$formcompany = new FormCompany($db);
$contactstatic=new Contact($db);
$userstatic=new User($db);


/* *************************************************************************** */
/*                                                                             */
/* Mode vue et edition                                                         */
/*                                                                             */
/* *************************************************************************** */
if (isset($mesg)) print $mesg;
$id = $_GET["facid"];
if ($id > 0)
{
	$facture = new FactureFournisseur($db);
	if ($facture->fetch($_GET['facid'], $user->societe_id) > 0)
	{
		$facture->fetch_thirdparty();

		$head = facturefourn_prepare_head($facture);

		dol_fiche_head($head, 'contact', $langs->trans('SupplierInvoice'), 0, 'bill');

		/*
		 *   Facture synthese pour rappel
		 */
		print '<table class="border" width="100%">';

		// Reference du facture
		print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
		print $html->showrefnav($facture,'facid','',1,'rowid','ref',$morehtmlref);
示例#2
0
     $facusing = new FactureFournisseur($db);
     $facusing->fetch($object->fk_facture_source);
     print ' (' . $langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)) . ')';
 }
 $facidavoir = $object->getListIdAvoirFromInvoice();
 if (count($facidavoir) > 0) {
     print ' (' . $langs->transnoentities("InvoiceHasAvoir");
     $i = 0;
     foreach ($facidavoir as $id) {
         if ($i == 0) {
             print ' ';
         } else {
             print ',';
         }
         $facavoir = new FactureFournisseur($db);
         $facavoir->fetch($id);
         print $facavoir->getNomUrl(1);
     }
     print ')';
 }
 // FIXME $facidnext is not defined
 /*
 if ($facidnext > 0)
 {
 	$facthatreplace=new FactureFournisseur($db);
 	$facthatreplace->fetch($facidnext);
 	print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
 }
 */
 print '</td></tr>';
 // Label
 /**
  * testFactureFournisseurDelete
  *
  * @param	int		$id		Id of supplier invoice
  * @return	void
  *
  * @depends	testFactureFournisseurOther
  * The depends says test is run only if previous is ok
  */
 public function testFactureFournisseurDelete($id)
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject = new FactureFournisseur($this->savdb);
     $result = $localobject->fetch($id);
     $result = $localobject->delete($id);
     print __METHOD__ . " id=" . $id . " result=" . $result . "\n";
     $this->assertLessThan($result, 0);
     return $result;
 }
示例#4
0
 foreach ($links as $key => $val) {
     if ($links[$key]['type'] == 'payment') {
         $paymentstatic->fetch($links[$key]['url_id']);
         $tmparray = $paymentstatic->getBillsArray('');
         foreach ($tmparray as $key => $val) {
             $invoicestatic->fetch($val);
             if ($accountelem) {
                 $accountelem .= ', ';
             }
             $accountelem .= $invoicestatic->ref;
         }
     } elseif ($links[$key]['type'] == 'payment_supplier') {
         $paymentsupplierstatic->fetch($links[$key]['url_id']);
         $tmparray = $paymentsupplierstatic->getBillsArray('');
         foreach ($tmparray as $key => $val) {
             $invoicesupplierstatic->fetch($val);
             if ($accountelem) {
                 $accountelem .= ', ';
             }
             $accountelem .= $invoicesupplierstatic->ref;
         }
     } elseif ($links[$key]['type'] == 'payment_sc') {
         $paymentsocialcontributionstatic->fetch($links[$key]['url_id']);
         if ($accountelem) {
             $accountelem .= ', ';
         }
         $accountelem .= $langs->transnoentitiesnoconv("SocialContribution") . ' ' . $paymentsocialcontributionstatic->ref;
     } elseif ($links[$key]['type'] == 'payment_vat') {
         $paymentvatstatic->fetch($links[$key]['url_id']);
         if ($accountelem) {
             $accountelem .= ', ';
/**
 * Delete preview files
 * @param   $db
 * @param   $objectid
 * @return  int
 */
function supplier_invoice_delete_preview($db, $objectid)
{
	global $langs,$conf;
    require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

	$comfourn = new FactureFournisseur($db,"",$objectid);
	$comfourn->fetch($objectid);
	$client = new Societe($db);
	$client->fetch($comfourn->socid);

	if ($conf->fournisseur->dir_output.'/facture')
	{
		$comfournref = dol_sanitizeFileName($comfourn->ref);
		$dir = $conf->facture->dir_output . "/" . $comfournref ;
		$file = $dir . "/" . $comfournref . ".pdf.png";

		if ( file_exists( $file ) && is_writable( $file ) )
		{
			if ( ! dol_delete_file($file) )
			{
				$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
				return 0;
			}
		}
	}

	return 1;
}
/**
 * Get list of invoices for third party
 *
 * @param	array		$authentication		Array of authentication information
 * @param	int			$idthirdparty		Id thirdparty
 * @return	array							Array result
 *
 */
function getSupplierInvoicesForThirdParty($authentication,$idthirdparty)
{
	global $db,$conf,$langs;

	dol_syslog("Function: getSupplierInvoicesForThirdParty login="******" idthirdparty=".$idthirdparty);

	if ($authentication['entity']) $conf->entity=$authentication['entity'];

    // Init and check authentication
    $objectresp=array();
    $errorcode='';$errorlabel='';
    $error=0;
    $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
    // Check parameters
	if (! $error && empty($idthirdparty))
	{
		$error++;
		$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id is not provided';
	}

	if (! $error)
	{
		$linesinvoice=array();

		$sql.='SELECT f.rowid as facid';
		$sql.=' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
		//$sql.=', '.MAIN_DB_PREFIX.'societe as s';
		//$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product = p.rowid';
		//$sql.=" WHERE f.fk_soc = s.rowid AND nom = '".$db->escape($idthirdparty)."'";
		//$sql.=" WHERE f.fk_soc = s.rowid AND nom = '".$db->escape($idthirdparty)."'";
        $sql.=" WHERE f.entity = ".$conf->entity;
		if ($idthirdparty != 'all') $sql.=" AND f.fk_soc = ".$db->escape($idthirdparty);

		$resql=$db->query($sql);
		if ($resql)
		{
			$num=$db->num_rows($resql);
			$i=0;
			while ($i < $num)
			{
                // En attendant remplissage par boucle
			    $obj=$db->fetch_object($resql);

			    $invoice=new FactureFournisseur($db);
			    $invoice->fetch($obj->facid);

				// Define lines of invoice
				$linesresp=array();
				foreach($invoice->lines as $line)
				{
   				    $linesresp[]=array(
    					'id'=>$line->rowid,
    					'type'=>$line->product_type,
                        'desc'=>dol_htmlcleanlastbr($line->description),
    					'total_net'=>$line->total_ht,
    					'total_vat'=>$line->total_tva,
    					'total'=>$line->total_ttc,
                        'vat_rate'=>$line->tva_tx,
                        'qty'=>$line->qty,
   				        'product_ref'=>$line->product_ref,
                        'product_label'=>$line->product_label,
                        'product_desc'=>$line->product_desc,
   				    );
				}

				// Now define invoice
				$linesinvoice[]=array(
					'id'=>$invoice->id,
				    'ref'=>$invoice->ref,
				    'ref_supplier'=>$invoice->ref_supplier,
				    'ref_ext'=>$invoice->ref_ext,
                    'fk_user_author' => $invoice->fk_user_author,
                    'fk_user_valid' => $invoice->fk_user_valid,
                    'fk_thirdparty' => $invoice->fk_soc,
				    'type'=>$invoice->type,
                    'status'=>$invoice->statut,
				    'total_net'=>$invoice->total_ht,
					'total_vat'=>$invoice->total_tva,
					'total'=>$invoice->total_ttc,
                    'date_creation'=>dol_print_date($invoice->datec,'dayhourrfc'),
                    'date_modification'=>dol_print_date($invoice->tms,'dayhourrfc'),
                    'date_invoice'=>dol_print_date($invoice->date,'dayhourrfc'),
                    'date_term'=>dol_print_date($invoice->date_echeance,'dayhourrfc'),
                    'label'=>$invoice->libelle,
                    'paid'=>$invoice->paye,
                    'note'=>$invoice->note,
                    'note_public'=>$invoice->note_public,
                    'close_code'=>$invoice->close_code,
                    'close_note'=>$invoice->close_note,

				    'lines' => $linesresp
				);

				$i++;
			}

			$objectresp=array(
		    	'result'=>array('result_code'=>'OK', 'result_label'=>''),
		        'invoices'=>$linesinvoice

			);
		}
		else
		{
			$error++;
			$errorcode=$db->lasterrno(); $errorlabel=$db->lasterror();
		}
	}

	if ($error)
	{
		$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
	}

	return $objectresp;
}
示例#7
0
 /**
  *	Create payment in database
  *
  *	@param		User	$user        			Object of creating user
  *	@param		int		$closepaidinvoices   	1=Also close payed invoices to paid, 0=Do nothing more
  *	@return     int         					id of created payment, < 0 if error
  */
 function create($user, $closepaidinvoices = 0)
 {
     global $langs, $conf;
     $error = 0;
     // Clean parameters
     $this->total = 0;
     foreach ($this->amounts as $key => $value) {
         $newvalue = price2num($value, 'MT');
         $this->amounts[$key] = $newvalue;
         $this->total += $newvalue;
     }
     $this->total = price2num($this->total);
     $this->db->begin();
     if ($this->total != 0) {
         $now = dol_now();
         $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn (';
         $sql .= 'datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
         $sql .= " VALUES ('" . $this->db->idate($now) . "',";
         $sql .= " '" . $this->db->idate($this->datepaye) . "', '" . $this->total . "', " . $this->paiementid . ", '" . $this->num_paiement . "', '" . $this->db->escape($this->note) . "', " . $user->id . ", 0)";
         dol_syslog("PaiementFourn::create", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if ($resql) {
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . 'paiementfourn');
             // Insere tableau des montants / factures
             foreach ($this->amounts as $key => $amount) {
                 $facid = $key;
                 if (is_numeric($amount) && $amount != 0) {
                     $amount = price2num($amount);
                     $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
                     $sql .= ' VALUES (' . $facid . ',' . $this->id . ',\'' . $amount . '\')';
                     $resql = $this->db->query($sql);
                     if ($resql) {
                         // If we want to closed payed invoices
                         if ($closepaidinvoices) {
                             $invoice = new FactureFournisseur($this->db);
                             $invoice->fetch($facid);
                             $paiement = $invoice->getSommePaiement();
                             //$creditnotes=$invoice->getSumCreditNotesUsed();
                             $creditnotes = 0;
                             //$deposits=$invoice->getSumDepositsUsed();
                             $deposits = 0;
                             $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
                             $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
                             if ($remaintopay == 0) {
                                 $result = $invoice->set_paid($user, '', '');
                             } else {
                                 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing.");
                             }
                         }
                     } else {
                         dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture ' . $facid);
                         $error++;
                     }
                 } else {
                     dol_syslog('PaiementFourn::Create Montant non numerique', LOG_ERR);
                 }
             }
             if (!$error) {
                 // Call trigger
                 $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
                 if ($result < 0) {
                     $error++;
                 }
                 // End call triggers
             }
         } else {
             $this->error = $this->db->lasterror();
             $error++;
         }
     } else {
         $this->error = "ErrorTotalIsNull";
         dol_syslog('PaiementFourn::Create Error ' . $this->error, LOG_ERR);
         $error++;
     }
     if ($this->total != 0 && $error == 0) {
         $this->db->commit();
         dol_syslog('PaiementFourn::Create Ok Total = ' . $this->total);
         return $this->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
示例#8
0
            exit;
        } else {
            $db->rollback();
        }
    }
}
/*
 * View
 */
$supplierstatic = new Societe($db);
$invoicesupplierstatic = new FactureFournisseur($db);
llxHeader();
$html = new Form($db);
if ($action == 'create' || $action == 'add_paiement') {
    $facture = new FactureFournisseur($db);
    $facture->fetch($facid);
    $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
    $dateinvoice = $datefacture == '' ? empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : 0 : $datefacture;
    $sql = 'SELECT s.nom, s.rowid as socid,';
    $sql .= ' f.rowid as ref, f.facnumber, f.amount, f.total_ttc as total';
    if (!$user->rights->societe->client->voir && !$socid) {
        $sql .= ", sc.fk_soc, sc.fk_user ";
    }
    $sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s, ' . MAIN_DB_PREFIX . 'facture_fourn as f';
    if (!$user->rights->societe->client->voir && !$socid) {
        $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
    }
    $sql .= ' WHERE f.fk_soc = s.rowid';
    $sql .= ' AND f.rowid = ' . $facid;
    if (!$user->rights->societe->client->voir && !$socid) {
        $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
 /**
  *  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 . '/fourn/class/fournisseur.facture.class.php';
     include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
     $facturestatic = new FactureFournisseur($db);
     $thirdpartytmp = new Fournisseur($db);
     $this->info_box_head = array('text' => $langs->trans("BoxTitleLast" . ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE ? "" : "Modified") . "SupplierBills", $max));
     if ($user->rights->fournisseur->facture->lire) {
         $sql = "SELECT s.nom as name, s.rowid as socid,";
         $sql .= " s.code_fournisseur,";
         $sql .= " s.logo,";
         $sql .= " f.rowid as facid, f.ref, f.ref_supplier,";
         $sql .= " f.total_ht,";
         $sql .= " f.total_tva,";
         $sql .= " f.total_ttc,";
         $sql .= " f.paye, f.fk_statut,";
         $sql .= ' f.datef as df,';
         $sql .= ' f.datec as datec,';
         $sql .= ' f.date_lim_reglement as datelimite, f.tms, f.type';
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
         $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn 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;
         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;
         }
         if ($conf->global->MAIN_LASTBOX_ON_OBJECT_DATE) {
             $sql .= " ORDER BY f.datef DESC, f.ref DESC ";
         } else {
             $sql .= " ORDER BY f.tms DESC, f.ref DESC ";
         }
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $num = $db->num_rows($result);
             $now = dol_now();
             $line = 0;
             $l_due_date = $langs->trans('Late') . ' (' . $langs->trans('DateEcheance') . ': %s)';
             while ($line < $num) {
                 $objp = $db->fetch_object($result);
                 $datelimite = $db->jdate($objp->datelimite);
                 $date = $db->jdate($objp->df);
                 $datem = $db->jdate($objp->tms);
                 $facturestatic->id = $objp->facid;
                 $facturestatic->ref = $objp->ref;
                 $facturestatic->total_ht = $objp->total_ht;
                 $facturestatic->total_tva = $objp->total_tva;
                 $facturestatic->total_ttc = $objp->total_ttc;
                 $thirdpartytmp->id = $objp->socid;
                 $thirdpartytmp->name = $objp->name;
                 $thirdpartytmp->fournisseur = 1;
                 $thirdpartytmp->code_fournisseur = $objp->code_fournisseur;
                 $thirdpartytmp->logo = $objp->logo;
                 $late = '';
                 if ($objp->paye == 0 && $datelimite && $datelimite < $now - $conf->facture->fournisseur->warning_delay) {
                     $late = img_warning(sprintf($l_due_date, dol_print_date($datelimite, 'day')));
                 }
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $facturestatic->getNomUrl(1), 'text2' => $late, 'asis' => 1);
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $objp->ref_supplier, 'tooltip' => $langs->trans('SupplierInvoice') . ': ' . ($objp->ref ? $objp->ref : $objp->facid) . '<br>' . $langs->trans('RefSupplier') . ': ' . $objp->ref_supplier, 'url' => DOL_URL_ROOT . "/fourn/facture/card.php?facid=" . $objp->facid);
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $thirdpartytmp->getNomUrl(1, 'supplier'), 'asis' => 1);
                 $this->info_box_contents[$line][] = array('td' => 'align="right"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency));
                 $this->info_box_contents[$line][] = array('td' => 'align="right"', 'text' => dol_print_date($date, 'day'));
                 $fac = new FactureFournisseur($db);
                 $fac->fetch($objp->facid);
                 $alreadypaid = $fac->getSommePaiement();
                 $this->info_box_contents[$line][] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 3, $alreadypaid, $objp->type));
                 $line++;
             }
             if ($num == 0) {
                 $this->info_box_contents[$line][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoModifiedSupplierBills"));
             }
             $db->free($result);
         } 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->transnoentities("ReadPermissionNotAllowed"));
     }
 }
 function get_origin($fk_origin, $origintype)
 {
     switch ($origintype) {
         case 'commande':
             require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php';
             $origin = new Commande($this->db);
             break;
         case 'shipping':
             require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
             $origin = new Expedition($this->db);
             break;
         case 'facture':
             require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
             $origin = new Facture($this->db);
             break;
         case 'order_supplier':
             require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
             $origin = new CommandeFournisseur($this->db);
             break;
         case 'invoice_supplier':
             require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
             $origin = new FactureFournisseur($this->db);
             break;
         default:
             return '';
             break;
     }
     $origin->fetch($fk_origin);
     return $origin->getNomUrl(1);
 }
示例#11
0
$facid = isset($_GET["facid"])?$_GET["facid"]:'';

// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'fournisseur', $facid, 'facture_fourn', 'facture');



/*
 * View
 */

llxHeader();

$fac = new FactureFournisseur($db);
$fac->fetch($_GET["facid"]);
$fac->info($_GET["facid"]);
$soc = new Societe($db, $fac->socid);
$soc->fetch($fac->socid);

$head = facturefourn_prepare_head($fac);
$titre=$langs->trans('SupplierInvoice');
dol_fiche_head($head, 'info', $langs->trans('SupplierInvoice'), 0, 'bill');

print '<table width="100%"><tr><td>';
dol_print_object_info($fac);
print '</td></tr></table>';

print '</div>';

$db->close();
示例#12
0
 $error = 0;
 $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
 $paiement_id = 0;
 $totalpayment = 0;
 $atleastonepaymentnotnull = 0;
 // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
 $tmpinvoice = new FactureFournisseur($db);
 foreach ($_POST as $key => $value) {
     if (substr($key, 0, 7) == 'amount_') {
         $cursorfacid = substr($key, 7);
         $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
         $totalpayment = $totalpayment + $amounts[$cursorfacid];
         if (!empty($amounts[$cursorfacid])) {
             $atleastonepaymentnotnull++;
         }
         $result = $tmpinvoice->fetch($cursorfacid);
         if ($result <= 0) {
             dol_print_error($db);
         }
         $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
         if ($amounts[$cursorfacid]) {
             // Check amount
             if ($amounts[$cursorfacid] && abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])) {
                 $addwarning = 1;
                 $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")) . ' ' . $langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
             }
             // Check date
             if ($datepaye && $datepaye < $tmpinvoice->date) {
                 $langs->load("errors");
                 //$error++;
                 setEventMessage($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), 'warnings');
示例#13
0
    /**
     *      A record into bank for payment with links between this bank record and invoices of payment.
     *      All payment properties must have been set first like after a call to create().
     *      @param      user                Object of user making payment
     *      @param      mode                'payment', 'payment_supplier'
     *      @param      label               Label to use in bank record
     *      @param      accountid           Id of bank account to do link with
     *      @param      emetteur_nom        Name of transmitter
     *      @param      emetteur_banque     Name of bank
     *      @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;
        $this->fk_account=$accountid;

        if ($conf->banque->enabled)
        {
            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);
            $acc->fetch($this->fk_account);

            $totalamount=$this->amount;
            if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility
            if ($mode == 'payment') $totalamount=$totalamount;
            if ($mode == 'payment_supplier') $totalamount=-$totalamount;

            // Insert payment into llx_bank
            $bank_line_id = $acc->addline($this->datepaye,
            $this->paiementid,  // Payment mode id or code ("CHQ or VIR for example")
            $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/fiche.php?id=';
                    if ($mode == 'payment_supplier') $url=DOL_URL_ROOT.'/fourn/paiement/fiche.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)
                {
                    $linkaddedforthirdparty=array();
                    foreach ($this->amounts as $key => $value)  // We should have always same third party but we loop in case of.
                    {
                        if ($mode == 'payment')
                        {
                            $fac = new Facture($this->db);
                            $fac->fetch($key);
                            $fac->fetch_thirdparty();
                            if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty
                            {
                                $result=$acc->add_url_line($bank_line_id, $fac->thirdparty->id,
                                DOL_URL_ROOT.'/comm/fiche.php?socid=', $fac->thirdparty->nom, 'company');
                                if ($result <= 0) dol_print_error($this->db);
                                $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)) // Not yet done for this thirdparty
                            {
                                $result=$acc->add_url_line($bank_line_id, $fac->thirdparty->id,
                                DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->thirdparty->nom, 'company');
                                if ($result <= 0) dol_print_error($this->db);
                                $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id;  // Mark as done for this thirdparty
                            }
                        }
                    }
                }

	            if (! $error && ! $notrigger)
				{
					// Appel des triggers
					include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
					$interface=new Interfaces($this->db);
					$result=$interface->run_triggers('PAYMENT_ADD_TO_BANK',$this,$user,$langs,$conf);
					if ($result < 0) { $error++; $this->errors=$interface->errors; }
					// Fin appel triggers
				}
            }
            else
            {
                $this->error=$acc->error;
                $error++;
            }
        }

        if (! $error)
        {
            return $bank_line_id;
        }
        else
        {
            return -1;
        }
    }
示例#14
0
    /**
     *      Show list of documents in a directory
     *      @param      upload_dir          Directory that was scanned
     *      @param      filearray           Array of files loaded by dol_dir_list function before calling this function
     *      @param      modulepart          Value for modulepart used by download wrapper
     *      @param      param               Parameters on sort links
     *      @param      forcedownload       Force to open dialog box "Save As" when clicking on file
     *      @param      relativepath        Relative path of docs (autodefined if not provided)
     *      @param      permtodelete        Permission to delete
     *      @param      useinecm            Change output for use in ecm module
     *      @param      textifempty         Text to show if filearray is empty
     *      @param      maxlength           Maximum length of file name shown
     *      @return     int                 <0 if KO, nb of files shown if OK
     */
    function list_of_autoecmfiles($upload_dir,$filearray,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0,$textifempty='',$maxlength=0)
    {
        global $user, $conf, $langs;
        global $bc;
        global $sortfield, $sortorder;

        // Affiche liste des documents existant
        if (empty($useinecm)) print_titre($langs->trans("AttachedFiles"));
        //else { $bc[true]=''; $bc[false]=''; };
        $url=$_SERVER["PHP_SELF"];
        print '<table width="100%" class="nobordernopadding">';
        print '<tr class="liste_titre">';
        print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"","",$param,'align="left"',$sortfield,$sortorder);
        print_liste_field_titre($langs->trans("Documents2"),$_SERVER["PHP_SELF"],"name","",$param,'align="left"',$sortfield,$sortorder);
        print_liste_field_titre($langs->trans("Size"),$_SERVER["PHP_SELF"],"size","",$param,'align="right"',$sortfield,$sortorder);
        print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"date","",$param,'align="center"',$sortfield,$sortorder);
        print_liste_field_titre('','','');
        print '</tr>';

        if ($modulepart == 'invoice')
        {
            include_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
            $object_static=new Facture($this->db);
        }
        if ($modulepart == 'invoice_supplier')
        {
            include_once(DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php');
            $object_static=new FactureFournisseur($this->db);
        }

        $var=true;
        foreach($filearray as $key => $file)
        {
            if (!is_dir($file['name'])
            && $file['name'] != '.'
            && $file['name'] != '..'
            && $file['name'] != 'CVS'
            && ! preg_match('/\.meta$/i',$file['name']))
            {
                // Define relative path used to store the file
                $relativefile=preg_replace('/'.preg_quote($upload_dir.'/','/').'/','',$file['fullname']);
                //print 'eeee'.$relativefile;
                //var_dump($file);
                $var=!$var;
                print '<tr '.$bc[$var].'>';
                print '<td>';
                $id='';$ref='';
                if ($modulepart == 'invoice')
                {
                    preg_match('/(.*)\/[^\/]+$/',$relativefile,$reg);
                    $ref=$reg[1];
                    $object_static->fetch('',$ref);
                    //print $relativefile.'rr'.$id;
                    print $object_static->getNomUrl(1,'document');
                }
                if ($modulepart == 'invoice_supplier')
                {
                    preg_match('/(\d+)\/[^\/]+$/',$relativefile,$reg);
                    $id=$reg[1];
                    $object_static->fetch($id);
                    //print $relativefile.'rr'.$id;
                    print $object_static->getNomUrl(1,'document');
                }
                print '</td>';
                print '<td>';
                //print "XX".$file['name']; //$file['name'] must be utf8
                print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
                if ($forcedownload) print '&attachment=1';
                print '&file='.urlencode($relativefile).'">';
                print img_mime($file['name'],$file['name'].' ('.dol_print_size($file['size'],0,0).')').' ';
                print dol_trunc($file['name'],$maxlength,'middle');
                print '</a>';
                print "</td>\n";
                print '<td align="right">'.dol_print_size($file['size'],1,1).'</td>';
                print '<td align="center">'.dol_print_date($file['date'],"dayhour").'</td>';
                print '<td align="right">';
                if (! empty($useinecm))  print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart;
                if ($forcedownload) print '&attachment=1';
                print '&file='.urlencode($relativefile).'">';
                print img_view().'</a> &nbsp; ';
                //if ($permtodelete) print '<a href="'.$url.'?id='.$object->id.'&section='.$_REQUEST["section"].'&action=delete&urlfile='.urlencode($file['name']).'">'.img_delete().'</a>';
                //else print '&nbsp;';
                print "</td></tr>\n";
            }
        }
        if (sizeof($filearray) == 0)
        {
            print '<tr '.$bc[$var].'><td colspan="4">';
            if (empty($textifempty)) print $langs->trans("NoFileFound");
            else print $textifempty;
            print '</td></tr>';
        }
        print "</table>";
        // Fin de zone
    }
示例#15
0
            exit;
        } else {
            $db->rollback();
        }
    }
}
/*
 * View
 */
$supplierstatic = new Societe($db);
$invoicesupplierstatic = new FactureFournisseur($db);
llxHeader();
$form = new Form($db);
if ($action == 'create' || $action == 'add_paiement') {
    $object = new FactureFournisseur($db);
    $object->fetch($facid);
    $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
    $dateinvoice = $datefacture == '' ? empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : 0 : $datefacture;
    $sql = 'SELECT s.nom, s.rowid as socid,';
    $sql .= ' f.rowid, f.ref, f.ref_supplier, f.amount, f.total_ttc as total';
    if (!$user->rights->societe->client->voir && !$socid) {
        $sql .= ", sc.fk_soc, sc.fk_user ";
    }
    $sql .= ' FROM ' . MAIN_DB_PREFIX . 'societe as s, ' . MAIN_DB_PREFIX . 'facture_fourn as f';
    if (!$user->rights->societe->client->voir && !$socid) {
        $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc";
    }
    $sql .= ' WHERE f.fk_soc = s.rowid';
    $sql .= ' AND f.rowid = ' . $facid;
    if (!$user->rights->societe->client->voir && !$socid) {
        $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id;
示例#16
0
$langs->load('other');
$langs->load("companies");
$id = GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('facid', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
// Security check
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
$object = new FactureFournisseur($db);
/*
 * Ajout d'un nouveau contact
 */
if ($action == 'addcontact' && $user->rights->fournisseur->facture->creer) {
    $result = $object->fetch($id);
    if ($result > 0 && $id > 0) {
        $contactid = GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid');
        $result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
    }
    if ($result >= 0) {
        Header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
        exit;
    } else {
        if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
            $langs->load("errors");
            $mesg = '<div class="error">' . $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType") . '</div>';
        } else {
            $mesg = '<div class="error">' . $object->error . '</div>';
        }
    }
$confirm = GETPOST('confirm', 'alpha');
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$line = GETPOST('lineid', 'int');
if ($user->societe_id) {
    $socid = $user->societe_id;
}
//$result=restrictedArea($user,'produit');
$mesg = '';
/*
 *	Actions
 */
// Add product to list
if ($action == 'add') {
    $fac = new FactureFournisseur($db);
    $fac->fetch($id);
    $error = 0;
    for ($i = 0; $i < sizeof($fac->lines); $i++) {
        $object = new Labelprint($db);
        $object->fk_product = $fac->lines[$i]->fk_product;
        $object->qty = $fac->lines[$i]->qty;
        $result = $object->create($user);
        if (!$result) {
            $error++;
        }
    }
    if ($error) {
        $mesg = '<div class="error">' . $object->error . '</div>';
    } else {
        $mesg = '<font class="ok">' . $langs->trans("LinesAdded") . '</font>';
    }
示例#18
0
 print '<td>&nbsp;</td>';
 print '<td>' . $langs->trans("Status") . '</td>';
 print '<td align="right">' . $langs->trans("Debit") . '</td>';
 print '<td align="right">' . $langs->trans("Credit") . '</td>';
 print '<td align="right">' . $langs->trans("Balance") . '</td>';
 print '<td>&nbsp;</td>';
 print '</tr>';
 if (!$num > 0) {
     print '<tr><td colspan="7">' . $langs->trans("NoInvoice") . '</td></tr>';
 }
 $solde = 0;
 // Boucle sur chaque facture
 for ($i = 0; $i < $num; $i++) {
     $objf = $db->fetch_object($resql);
     $fac = new FactureFournisseur($db);
     $ret = $fac->fetch($objf->facid);
     if ($ret < 0) {
         print $fac->error . "<br>";
         continue;
     }
     $totalpaye = $fac->getSommePaiement();
     $var = !$var;
     print "<tr {$bc[$var]}>";
     print "<td align=\"center\">" . dol_print_date($fac->date) . "</td>\n";
     print "<td><a href=\"facture/fiche.php?facid={$fac->id}\">" . img_object($langs->trans("ShowBill"), "bill") . " " . $fac->ref . "</a></td>\n";
     print '<td aling="left">' . $fac->getLibStatut(2, $totalpaye) . '</td>';
     print '<td align="right">' . price($fac->total_ttc) . "</td>\n";
     $solde = $solde + $fac->total_ttc;
     print '<td align="right">&nbsp;</td>';
     print '<td align="right">' . price($solde) . "</td>\n";
     // Author
示例#19
0
     $i = 0;
     foreach ($facidavoir as $id) {
         if ($i == 0) {
             print ' ';
         } else {
             print ',';
         }
         $facavoir = new FactureFournisseur($db);
         $facavoir->fetch($id);
         print $facavoir->getNomUrl(1);
     }
     print ')';
 }
 if (isset($facidnext) && $facidnext > 0) {
     $facthatreplace = new FactureFournisseur($db);
     $facthatreplace->fetch($facidnext);
     print ' (' . $langs->transnoentities("ReplacedByInvoice", $facthatreplace->getNomUrl(1)) . ')';
 }
 print '</td></tr>';
 // Label
 print '<tr><td>' . $form->editfieldkey("Label", 'label', $object->label, $object, $user->rights->fournisseur->facture->creer) . '</td>';
 print '<td colspan="3">' . $form->editfieldval("Label", 'label', $object->label, $object, $user->rights->fournisseur->facture->creer) . '</td>';
 /*
  * List of payments
  */
 $nbrows = 9;
 $nbcols = 2;
 if (!empty($conf->projet->enabled)) {
     $nbrows++;
 }
 if (!empty($conf->banque->enabled)) {
 /**
  *	Load an object from its id and create a new one in database
  *
  *	@param      int		$fromid     	Id of object to clone
  *	@param		int		$invertdetail	Reverse sign of amounts for lines
  * 	@return		int						New id of clone
  */
 function createFromClone($fromid, $invertdetail = 0)
 {
     global $user, $langs;
     $error = 0;
     $object = new FactureFournisseur($this->db);
     $object->context['createfromclone'] = 'createfromclone';
     $this->db->begin();
     // Load source object
     $object->fetch($fromid);
     $object->id = 0;
     $object->statut = self::STATUS_DRAFT;
     // Clear fields
     $object->ref_supplier = $langs->trans("CopyOf") . ' ' . $object->ref_supplier;
     $object->author = $user->id;
     $object->user_valid = '';
     $object->fk_facture_source = 0;
     $object->date_creation = '';
     $object->date_validation = '';
     $object->date = '';
     $object->date_echeance = '';
     $object->ref_client = '';
     $object->close_code = '';
     $object->close_note = '';
     // Loop on each line of new invoice
     foreach ($object->lines as $i => $line) {
         if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x2) == 0x2) {
             unset($object->lines[$i]);
         }
     }
     // Create clone
     $result = $object->create($user);
     // Other options
     if ($result < 0) {
         $this->error = $object->error;
         $error++;
     }
     if (!$error) {
     }
     unset($object->context['createfromclone']);
     // End
     if (!$error) {
         $this->db->commit();
         return $object->id;
     } else {
         $this->db->rollback();
         return -1;
     }
 }
示例#21
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;
     }
 }
示例#22
0
 */
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php';
$langs->load('bills');
$id = GETPOST("facid", 'int');
// Security check
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
/*
 * View
 */
llxHeader();
$object = new FactureFournisseur($db);
$object->fetch($id);
$object->info($id);
$soc = new Societe($db);
$soc->fetch($object->socid);
$head = facturefourn_prepare_head($object);
$titre = $langs->trans('SupplierInvoice');
dol_fiche_head($head, 'info', $langs->trans('SupplierInvoice'), 0, 'bill');
print '<table width="100%"><tr><td>';
dol_print_object_info($object);
print '</td></tr></table>';
print '</div>';
llxFooter();
$db->close();
示例#23
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 . "/fourn/class/fournisseur.facture.class.php";
     $facturestatic = new FactureFournisseur($db);
     $this->info_box_head = array('text' => $langs->trans("BoxTitleLastSupplierBills", $max));
     if ($user->rights->fournisseur->facture->lire) {
         $sql = "SELECT s.nom, s.rowid as socid,";
         $sql .= " f.rowid as facid, f.facnumber, f.amount,";
         $sql .= " f.paye, f.fk_statut,";
         $sql .= ' f.datef as df,';
         $sql .= ' f.datec as datec,';
         $sql .= ' f.date_lim_reglement as datelimite, f.tms, f.type';
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
         $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn 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;
         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 = 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);
                 $datec = $db->jdate($objp->datec);
                 $late = '';
                 if ($objp->paye == 0 && $datelimite < $now - $conf->facture->fournisseur->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 . "/fourn/facture/fiche.php?facid=" . $objp->facid);
                 $this->info_box_contents[$i][1] = array('td' => 'align="left"', 'text' => $objp->facnumber, 'text2' => $late, 'url' => DOL_URL_ROOT . "/fourn/facture/fiche.php?facid=" . $objp->facid);
                 $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"', 'logo' => 'company', 'url' => DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $objp->socid);
                 $this->info_box_contents[$i][3] = array('td' => 'align="left"', 'text' => $objp->nom, 'url' => DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $objp->socid);
                 $this->info_box_contents[$i][4] = array('td' => 'align="right"', 'text' => dol_print_date($datec, 'day'));
                 $fac = new FactureFournisseur($db);
                 $fac->fetch($objp->facid);
                 $alreadypaid = $fac->getSommePaiement();
                 $this->info_box_contents[$i][5] = array('td' => 'align="right" width="18"', 'text' => $facturestatic->LibStatut($objp->paye, $objp->fk_statut, 3, $alreadypaid, $objp->type));
                 $i++;
             }
             if ($num == 0) {
                 $this->info_box_contents[$i][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoModifiedSupplierBills"));
             }
         } else {
             dol_print_error($db);
         }
     } else {
         $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->transnoentities("ReadPermissionNotAllowed"));
     }
 }
示例#24
0
	/**
	 *    Create payment in database
	 *    @param      user        			Object of creating user
	 *    @param       closepaidinvoices   	1=Also close payed invoices to paid, 0=Do nothing more
	 *    @return     int         			id of created payment, < 0 if error
	 */
	function create($user,$closepaidinvoices=0)
	{
		global $langs,$conf;

		$error = 0;

		// Clean parameters
		$this->total = 0;
		foreach ($this->amounts as $key => $value)
		{
			$value = price2num($value);
			$val = round($value, 2);
			$this->amounts[$key] = $val;
			$this->total += $val;
		}
		$this->total = price2num($this->total);


		$this->db->begin();

		if ($this->total <> 0) // On accepte les montants negatifs
		{
			$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
			$sql.= 'datec, datep, amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
			$sql.= ' VALUES ('.$this->db->idate(mktime()).',';
			$sql.= " ".$this->db->idate($this->datepaye).", '".$this->total."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.", 0)";

			dol_syslog("PaiementFourn::create sql=".$sql);
			$resql = $this->db->query($sql);
			if ($resql)
			{
				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');

				// Insere tableau des montants / factures
				foreach ($this->amounts as $key => $amount)
				{
					$facid = $key;
					if (is_numeric($amount) && $amount <> 0)
					{
						$amount = price2num($amount);
						$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount)';
						$sql .= ' VALUES ('.$facid.','. $this->id.',\''.$amount.'\')';
						$resql=$this->db->query($sql);
						if ($resql)
						{
							// If we want to closed payed invoices
						    if ($closepaidinvoices)
						    {
						        $invoice=new FactureFournisseur($this->db);
						        $invoice->fetch($facid);
	                            $paiement = $invoice->getSommePaiement();
	                            //$creditnotes=$invoice->getSumCreditNotesUsed();
	                            $creditnotes=0;
	                            //$deposits=$invoice->getSumDepositsUsed();
	                            $deposits=0;
	                            $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
	                            $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
	                            if ($remaintopay == 0)
	                            {
	    					        $result=$invoice->set_paid($user,'','');
	                            }
	                            else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing.");
							}
						}
						else
						{
							dol_syslog('Paiement::Create Erreur INSERT dans paiement_facture '.$facid);
							$error++;
						}
						
					}
					else
					{
						dol_syslog('PaiementFourn::Create Montant non numerique',LOG_ERR);
					}
				}

				if (! $error)
				{
		            // Appel des triggers
		            include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
		            $interface=new Interfaces($this->db);
		            $result=$interface->run_triggers('PAYMENT_SUPPLIER_CREATE',$this,$user,$langs,$conf);
					if ($result < 0) { $error++; $this->errors=$interface->errors; }
		            // Fin appel triggers
				}
			}
			else
			{
				$this->error=$this->db->lasterror();
				dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
				$error++;
			}
		}
		else
		{
			$this->error="ErrorTotalIsNull";
			dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
			$error++;
		}

		if ($this->total <> 0 && $error == 0) // On accepte les montants negatifs
		{
			$this->db->commit();
			dol_syslog('PaiementFourn::Create Ok Total = '.$this->total);
			return $this->id;
		}
		else
		{
			$this->db->rollback();
			return -1;
		}
	}