/**
  * testFactureFournisseurCreate
  *
  * @return int
  */
 public function testFactureFournisseurCreate()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $localobject = new FactureFournisseur($this->savdb);
     $localobject->initAsSpecimen();
     $result = $localobject->create($user);
     $this->assertLessThan($result, 0);
     print __METHOD__ . " result=" . $result . "\n";
     return $result;
 }
 /**
  *	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;
     }
 }
示例#3
0
			/*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs))
			{
				$element = $regs[1];
				$subelement = $regs[2];
			}*/

			// For compatibility
    		if ($element == 'order')    { $element = $subelement = 'commande'; }
    		if ($element == 'propal')   { $element = 'comm/propal'; $subelement = 'propal'; }
    		if ($element == 'contract') { $element = $subelement = 'contrat'; }
    		if ($element == 'order_supplier') { $element = 'fourn'; $subelement = 'fournisseur.commande'; }

			$facfou->origin 	= $_POST['origin'];
			$facfou->origin_id = $_POST['originid'];

			$facid = $facfou->create($user);

        	// Add lines
			if ($facid > 0)
			{
				require_once(DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php');
				$classname = ucfirst($subelement);
    			if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur';
				$srcobject = new $classname($db);

				$result=$srcobject->fetch($_POST['originid']);
				if ($result > 0)
				{
					$lines = $srcobject->lines;
					if (empty($lines) && method_exists($srcobject,'fetch_lines'))  $lines = $srcobject->fetch_lines();
 $object->date_echeance = $datedue;
 $object->note_public = GETPOST('note_public');
 $object->note_private = GETPOST('note_private');
 $object->cond_reglement_id = GETPOST('cond_reglement_id');
 $object->mode_reglement_id = GETPOST('mode_reglement_id');
 $projectid = GETPOST('projectid');
 if ($projectid > 0) {
     $object->fk_project = $projectid;
 }
 // Auto calculation of date due if not filled by user
 if (empty($object->date_echeance)) {
     $object->date_echeance = $object->calculate_date_lim_reglement();
 }
 if ($_POST['origin'] && $_POST['originid']) {
     $object->linked_objects = $orders_id;
     $id = $object->create($user);
     if ($id > 0) {
         foreach ($orders_id as $origin => $origin_id) {
             $origin_id = !empty($origin_id) ? $origin_id : $orders_id[$ii];
             $object->add_object_linked($_POST['origin'], $origin_id);
         }
         while ($ii < $nn) {
             $objectsrc = new CommandeFournisseur($db);
             dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines");
             $result = $objectsrc->fetch($orders_id[$ii]);
             if ($result > 0) {
                 $lines = $objectsrc->lines;
                 if (empty($lines) && method_exists($objectsrc, 'fetch_lines')) {
                     $objectsrc->fetch_lines();
                     $lines = $objectsrc->lines;
                 }
 function createFacture(&$object, &$TLine)
 {
     global $user, $conf, $langs, $db;
     dol_include_once('/fourn/class/fournisseur.facture.class.php');
     $facture = new FactureFournisseur($db);
     $facture->origin = $object->element;
     $facture->origin_id = $object->id;
     $facture->ref = '';
     $facture->ref_supplier = '';
     //$facture->ref_supplier  = $object->ref_supplier;
     $facture->socid = $object->socid;
     $facture->libelle = $object->libelle;
     $object->date = time();
     $facture->note_public = $object->note_public;
     $facture->note_private = $object->note_private;
     $facture->cond_reglement_id = $object->cond_reglement_id;
     $facture->fk_account = $object->fk_account;
     $facture->fk_project = empty($object->fk_project) ? null : $object->fk_project;
     $facture->fk_incoterms = $object->fk_incoterms;
     $facture->location_incoterms = $object->location_incoterms;
     $facture->ref_supplier = time();
     $facture->date_echeance = $facture->calculate_date_lim_reglement();
     foreach ($TLine as &$row) {
         $line = $row->line;
         $line->qty = $row->qty;
         $line->id = 0;
         $facture->lines[] = $line;
     }
     $res = $facture->create($user);
     if ($res > 0) {
         header('location:' . dol_buildpath('/fourn/facture/card.php?action=editref_supplier&id=' . $res, 1));
         exit;
     } else {
         //var_dump($res, $facture);
         setEventMessage("ImpossibleToCreateInvoice", "errors");
     }
 }