/**
  *  Output record line into file
  *
  *  @param      array		$array_selected_sorted      Array with list of field to export
  *  @param      resource	$objp                       A record from a fetch with all fields from select
  *  @param      Translate	$outputlangs                Object lang to translate values
  *  @param		array		$array_types				Array with types of fields
  * 	@return		int										<0 if KO, >0 if OK
  */
 function write_record($array_selected_sorted, $objp, $outputlangs, $array_types)
 {
     global $conf;
     // Create a format for the column headings
     if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
         $outputlangs->charset_output = 'ISO-8859-1';
         // Because Excel 5 format is ISO
     }
     // Define first row
     $this->col = 0;
     foreach ($array_selected_sorted as $code => $value) {
         if (strpos($code, ' as ') == 0) {
             $alias = str_replace(array('.', '-'), '_', $code);
         } else {
             $alias = substr($code, strpos($code, ' as ') + 4);
         }
         if (empty($alias)) {
             dol_print_error('', 'Bad value for field with code=' . $code . '. Try to redefine export.');
         }
         $newvalue = $objp->{$alias};
         $newvalue = $this->excel_clean($newvalue);
         $typefield = isset($array_types[$code]) ? $array_types[$code] : '';
         // Traduction newvalue
         if (preg_match('/^\\((.*)\\)$/i', $newvalue, $reg)) {
             $newvalue = $outputlangs->transnoentities($reg[1]);
         } else {
             $newvalue = $outputlangs->convToOutputCharset($newvalue);
         }
         if (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$/i', $newvalue)) {
             if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
                 $formatdate = $this->workbook->addformat();
                 $formatdate->set_num_format('yyyy-mm-dd');
                 //$formatdate->set_num_format(0x0f);
                 $arrayvalue = preg_split('/[.,]/', xl_parse_date($newvalue));
                 //print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
                 $newvalue = strval($arrayvalue[0]) . '.' . strval($arrayvalue[1]);
                 // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
                 $this->worksheet->write($this->row, $this->col, $newvalue, PHPExcel_Shared_Date::PHPToExcel($formatdate));
             } else {
                 $newvalue = dol_stringtotime($newvalue);
                 $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, PHPExcel_Shared_Date::PHPToExcel($newvalue));
                 $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate();
                 $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd');
             }
         } elseif (preg_match('/^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/i', $newvalue)) {
             if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
                 $formatdatehour = $this->workbook->addformat();
                 $formatdatehour->set_num_format('yyyy-mm-dd hh:mm:ss');
                 //$formatdatehour->set_num_format(0x0f);
                 $arrayvalue = preg_split('/[.,]/', xl_parse_date($newvalue));
                 //print "x".$arrayvalue[0].'.'.strval($arrayvalue[1]).'<br>';
                 $newvalue = strval($arrayvalue[0]) . '.' . strval($arrayvalue[1]);
                 // $newvalue=strval(36892.521); directly does not work because . will be convert into , later
                 $this->worksheet->write($this->row, $this->col, $newvalue, $formatdatehour);
             } else {
                 $newvalue = dol_stringtotime($newvalue);
                 $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, PHPExcel_Shared_Date::PHPToExcel($newvalue));
                 $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate();
                 $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('yyyy-mm-dd h:mm:ss');
             }
         } else {
             if (!empty($conf->global->MAIN_USE_PHP_WRITEEXCEL)) {
                 $this->worksheet->write($this->row, $this->col, $newvalue);
             } else {
                 if ($typefield == 'Text' || $typefield == 'TextAuto') {
                     //$this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row+1)->setValueExplicit($newvalue, PHPExcel_Cell_DataType::TYPE_STRING);
                     $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, (string) $newvalue);
                     $coord = $this->workbook->getActiveSheet()->getCellByColumnAndRow($this->col, $this->row + 1)->getCoordinate();
                     $this->workbook->getActiveSheet()->getStyle($coord)->getNumberFormat()->setFormatCode('@');
                     $this->workbook->getActiveSheet()->getStyle($coord)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
                 } else {
                     $this->workbook->getActiveSheet()->SetCellValueByColumnAndRow($this->col, $this->row + 1, $newvalue);
                 }
             }
         }
         $this->col++;
     }
     $this->row++;
     return 0;
 }
Esempio n. 2
0
}
if (!empty($conf->ficheinter->enabled)) {
    $langs->load("interventions");
}
$projectid = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha');
$datesrfc = GETPOST('datesrfc');
$dateerfc = GETPOST('dateerfc');
$dates = dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
$datee = dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
if (empty($dates) && !empty($datesrfc)) {
    $dates = dol_stringtotime($datesrfc);
}
if (empty($datee) && !empty($dateerfc)) {
    $datee = dol_stringtotime($dateerfc);
}
if (!isset($_POST['datesrfc']) && !isset($_POST['datesday']) && !empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR)) {
    $new = dol_now();
    $tmp = dol_getdate($new);
    //$datee=$now
    //$dates=dol_time_plus_duree($datee, -1, 'y');
    $dates = dol_get_first_day($tmp['year'], 1);
}
if ($projectid == '' && $ref == '') {
    dol_print_error('', 'Bad parameter');
    exit;
}
$mine = $_REQUEST['mode'] == 'mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1;	// Special for projects
$project = new Project($db);
Esempio n. 3
0
     $invoice->lines[] = $invoiceline;
 }
 $invoice->socid = $conf_fksoc;
 $invoice->date_creation = $now;
 $invoice->date = $now;
 $invoice->date_lim_reglement = 0;
 $invoice->total_ht = $obj_facturation->prixTotalHt();
 $invoice->total_tva = $obj_facturation->montantTva();
 $invoice->total_ttc = $obj_facturation->prixTotalTtc();
 $invoice->note = $note;
 $invoice->cond_reglement_id = $cond_reglement_id;
 $invoice->mode_reglement_id = $mode_reglement_id;
 //print "c=".$invoice->cond_reglement_id." m=".$invoice->mode_reglement_id; exit;
 // Si paiement differe ...
 if ($obj_facturation->getSetPaymentMode() == 'DIF') {
     $resultcreate = $invoice->create($user, 0, dol_stringtotime($obj_facturation->paiementLe()));
     if ($resultcreate > 0) {
         $resultvalid = $invoice->validate($user, $obj_facturation->numInvoice());
     } else {
         $error++;
     }
     $id = $invoice->id;
 } else {
     $resultcreate = $invoice->create($user, 0, 0);
     if ($resultcreate > 0) {
         $resultvalid = $invoice->validate($user, $obj_facturation->numInvoice(), isset($_SESSION["CASHDESK_ID_WAREHOUSE"]) ? $_SESSION["CASHDESK_ID_WAREHOUSE"] : 0);
         $id = $invoice->id;
         // Add the payment
         $payment = new Paiement($db);
         $payment->datepaye = $now;
         $payment->bank_account = $conf_fkaccount;
Esempio n. 4
0
	function fetch($id, $user=0)
	{
		global $langs;

		$langs->load("companies");

		$sql = "SELECT c.rowid, c.fk_soc, c.civilite as civilite_id, c.name, c.firstname,";
		$sql.= " c.address, c.cp, c.ville,";
		$sql.= " c.fk_pays,";
		$sql.= " c.fk_departement,";
		$sql.= " c.birthday,";
		$sql.= " c.poste, c.phone, c.phone_perso, c.phone_mobile, c.fax, c.email, c.jabberid,";
		$sql.= " c.priv, c.note, c.default_lang, c.canvas,";
		$sql.= " p.libelle as pays, p.code as pays_code,";
		$sql.= " d.nom as departement, d.code_departement as departement_code,";
		$sql.= " u.rowid as user_id, u.login as user_login,";
		$sql.= " s.nom as socname, s.address as socaddress, s.cp as soccp, s.ville as soccity, s.default_lang as socdefault_lang";
		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c";
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_pays as p ON c.fk_pays = p.rowid";
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON c.fk_departement = d.rowid";
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON c.rowid = u.fk_socpeople";
		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON c.fk_soc = s.rowid";
		$sql.= " WHERE c.rowid = ". $id;

		dol_syslog("Contact::fetch sql=".$sql);
		$resql=$this->db->query($sql);
		if ($resql)
		{
			if ($this->db->num_rows($resql))
			{
				$obj = $this->db->fetch_object($resql);

				$this->id				= $obj->rowid;
				$this->ref				= $obj->rowid;
				$this->civilite_id		= $obj->civilite_id;
				$this->name				= $obj->name;
				$this->firstname		= $obj->firstname;
				$this->nom				= $obj->name;			// TODO deprecated
				$this->prenom			= $obj->firstname;		// TODO deprecated

				$this->address			= $obj->address;
				$this->adresse			= $obj->address; 		// TODO deprecated
				$this->cp				= $obj->cp;				// TODO deprecated
				$this->zip				= $obj->cp;
				$this->ville			= $obj->ville;			// TODO deprecated
				$this->town				= $obj->ville;

				$this->fk_departement	= $obj->fk_departement;
				$this->departement_code = $obj->departement_code;
				$this->departement		= $obj->departement;	// TODO deprecated
				$this->state			= $obj->departement;

				$this->fk_pays			= $obj->fk_pays;
				$this->pays_code		= $obj->fk_pays?$obj->pays_code:'';
				$this->pays				= ($obj->fk_pays > 0)?$langs->transnoentitiesnoconv("Country".$obj->pays_code):'';
				$this->country			= ($obj->fk_pays > 0)?$langs->transnoentitiesnoconv("Country".$obj->pays_code):'';

				$this->socid			= $obj->fk_soc;
				$this->socname			= $obj->socname;
				$this->poste			= $obj->poste;

				$this->phone_pro		= trim($obj->phone);
				$this->fax				= trim($obj->fax);
				$this->phone_perso		= trim($obj->phone_perso);
				$this->phone_mobile		= trim($obj->phone_mobile);

				$this->email			= $obj->email;
				$this->jabberid			= $obj->jabberid;
				$this->priv				= $obj->priv;
				$this->mail				= $obj->email;

				$this->birthday			= dol_stringtotime($obj->birthday);
				//print "fetch: ".$obj->birthday.'-'.$this->birthday;
				$this->birthday_alert 	= $obj->birthday_alert;
				$this->note				= $obj->note;
				$this->default_lang		= $obj->default_lang;
				$this->user_id			= $obj->user_id;
				$this->user_login		= $obj->user_login;
				$this->canvas			= $obj->canvas;

				// Recherche le user Dolibarr lie a ce contact
				$sql = "SELECT u.rowid ";
				$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
				$sql .= " WHERE u.fk_socpeople = ". $this->id;

				$resql=$this->db->query($sql);
				if ($resql)
				{
					if ($this->db->num_rows($resql))
					{
						$uobj = $this->db->fetch_object($resql);

						$this->user_id = $uobj->rowid;
					}
					$this->db->free($resql);
				}
				else
				{
					$this->error=$this->db->error();
					dol_syslog("Contact::fetch ".$this->error, LOG_ERR);
					return -1;
				}

				// Charge alertes du user
				if ($user)
				{
					$sql = "SELECT fk_user";
					$sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
					$sql .= " WHERE fk_user = "******" AND fk_contact = ".$id;

					$resql=$this->db->query($sql);
					if ($resql)
					{
						if ($this->db->num_rows($resql))
						{
							$obj = $this->db->fetch_object($resql);

							$this->birthday_alert = 1;
						}
						$this->db->free($resql);
					}
					else
					{
						$this->error=$this->db->error();
						dol_syslog("Contact::fetch ".$this->error, LOG_ERR);
						return -1;
					}
				}

				return 1;
			}
			else
			{
				$this->error=$langs->trans("RecordNotFound");
				return 0;
			}
		}
		else
		{
			$this->error=$this->db->error();
			dol_syslog("Contact::fetch ".$this->error, LOG_ERR);
			return -1;
		}
	}
Esempio n. 5
0
 $icalevents = array_merge($icalevents, $moreicalevents);
 // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
 foreach ($icalevents as $icalevent) {
     //var_dump($icalevent);
     //print $icalevent['SUMMARY'].'->'.var_dump($icalevent).'<br>';exit;
     if (!empty($icalevent['RRULE'])) {
         continue;
     }
     // We found a repeatable event. It was already split into unitary events, so we discard general rule.
     // Create a new object action
     $event = new ActionComm($db);
     $addevent = false;
     if (isset($icalevent['DTSTART;VALUE=DATE'])) {
         // For full day events, date are also GMT but they wont but converted using tz during output
         $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
         $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1;
         // We remove one second to get last second of day
         //print 'x'.$datestart.'-'.$dateend;exit;
         //print dol_print_date($dateend,'dayhour','gmt');
         $event->fulldayevent = true;
         $addevent = true;
     } elseif (!is_array($icalevent['DTSTART'])) {
         $datestart = $icalevent['DTSTART'];
         $dateend = $icalevent['DTEND'];
         $datestart += +($offsettz * 3600);
         $dateend += +($offsettz * 3600);
         $addevent = true;
         //var_dump($offsettz);
         //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
     } elseif (isset($icalevent['DTSTART']['unixtime'])) {
         $datestart = $icalevent['DTSTART']['unixtime'];
Esempio n. 6
0
        $icalevents=array();
        if (is_array($ical->get_event_list())) $icalevents=array_merge($icalevents,$ical->get_event_list());
        if (is_array($ical->get_freebusy_list())) $icalevents=array_merge($icalevents,$ical->get_freebusy_list());

        if(count($icalevents)>0)
        {
            foreach($icalevents as $icalevent)
            {
                // Create a new object action
                $event=new ActionComm($db);
                $addevent = false;
                if($icalevent['DTSTART;VALUE=DATE']) //fullday event
                {
                    // For full day events, date are also GMT but they wont but converted using tz during output
                    $datestart=dol_stringtotime($icalevent['DTSTART;VALUE=DATE'],1);
                    $dateend=dol_stringtotime($icalevent['DTEND;VALUE=DATE'],1)-1;  // We remove one second to get last second of day
                    //print 'x'.$datestart.'-'.$dateend;exit;
                    //print dol_print_date($dateend,'dayhour','gmt');
                    $event->fulldayevent=true;
                    $addevent=true;
                }
                elseif (is_array($icalevent['RRULE'])) //repeatable event
                {
                    $addevent=false; //TODO: a faire
                }
                elseif(!is_array($icalevent['DTSTART'])) //non-repeatable and not fullday event
                {
                    $datestart=$icalevent['DTSTART'];
                    $dateend=$icalevent['DTEND'];
                    $addevent=true;
                }
}
if ($suser) {
    $sql .= ' AND u.login LIKE "%' . $db->escape($suser) . '%"';
}
if ($sttc) {
    $sql .= ' AND cf.total_ttc = ' . price2num($sttc);
}
if ($sdate)
{
    if (GETPOST('search_datemonth', 'int') && GETPOST('search_dateday', 'int') && GETPOST('search_dateyear', 'int'))
    {
	    $date = dol_mktime(0, 0, 0, GETPOST('search_datemonth', 'int'), GETPOST('search_dateday', 'int'), GETPOST('search_dateyear', 'int'));
    }
    else
    {
        $date = dol_stringtotime($sdate);
    }
    $sql .= " AND cf.date_creation = '" . $db->idate($date) . "'";
}
if ($sall) {
    $sql .= ' AND (cf.ref LIKE "%' . $db->escape($sall) . '%" ';
    $sql .= 'OR cf.note LIKE "%' . $db->escape($sall) . '%")';
}
if (!empty($socid)) {
    $sql .= ' AND s.rowid = ' . $socid;
}

if (GETPOST('statut', 'int')) {
    $sql .= ' AND fk_statut = ' . GETPOST('statut', 'int');
}
$sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
Esempio n. 8
0
 if ($test && $goontestloop) {
     $login = checkLoginPassEntity($usertotest, $passwordtotest, $entitytotest, $authmode);
     if ($login) {
         $dol_authmode = $conf->authmode;
         // This properties is defined only when logged, to say what mode was successfully used
         $dol_tz = $_POST["tz"];
         $dol_tz_string = $_POST["tz_string"];
         $dol_tz_string = preg_replace('/\\s*\\(.+\\)$/', '', $dol_tz_string);
         $dol_tz_string = preg_replace('/,/', '/', $dol_tz_string);
         $dol_tz_string = preg_replace('/\\s/', '_', $dol_tz_string);
         $dol_dst = 0;
         if (isset($_POST["dst_first"]) && isset($_POST["dst_second"])) {
             include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
             $datenow = dol_now();
             $datefirst = dol_stringtotime($_POST["dst_first"]);
             $datesecond = dol_stringtotime($_POST["dst_second"]);
             if ($datenow >= $datefirst && $datenow < $datesecond) {
                 $dol_dst = 1;
             }
         }
         //print $datefirst.'-'.$datesecond.'-'.$datenow.'-'.$dol_tz.'-'.$dol_tzstring.'-'.$dol_dst; exit;
     }
     if (!$login) {
         dol_syslog('Bad password, connexion refused', LOG_DEBUG);
         $langs->load('main');
         $langs->load('errors');
         // Bad password. No authmode has found a good password.
         $user->trigger_mesg = $langs->trans("ErrorBadLoginPassword") . ' - login=' . GETPOST("username", "alpha", 2);
         // We set a generic message if not defined inside function checkLoginPassEntity or subfunctions
         if (empty($_SESSION["dol_loginmesg"])) {
             $_SESSION["dol_loginmesg"] = $langs->trans("ErrorBadLoginPassword");
Esempio n. 9
0
     print 'Rebuild PDF for all invoices' . "\n";
 }
 if ($value == 'filter=date') {
     $found = true;
     $option .= (empty($option) ? '' : '_') . 'date_' . $argv[$key + 1] . '_' . $argv[$key + 2];
     $filter[] = 'date';
     $dateafterdate = dol_stringtotime($argv[$key + 1]);
     $datebeforedate = dol_stringtotime($argv[$key + 2]);
     print 'Rebuild PDF for invoices validated between ' . dol_print_date($dateafterdate, 'day', 'gmt') . " and " . dol_print_date($datebeforedate, 'day', 'gmt') . ".\n";
 }
 if ($value == 'filter=payments') {
     $found = true;
     $option .= (empty($option) ? '' : '_') . 'payments_' . $argv[$key + 1] . '_' . $argv[$key + 2];
     $filter[] = 'payments';
     $paymentdateafter = dol_stringtotime($argv[$key + 1] . '000000');
     $paymentdatebefore = dol_stringtotime($argv[$key + 2] . '235959');
     if (empty($paymentdateafter) || empty($paymentdatebefore)) {
         print 'Error: Bad date format or value' . "\n";
         exit(-1);
     }
     print 'Rebuild PDF for invoices with at least one payment between ' . dol_print_date($paymentdateafter, 'day', 'gmt') . " and " . dol_print_date($paymentdatebefore, 'day', 'gmt') . ".\n";
 }
 if ($value == 'filter=nopayment') {
     $found = true;
     $option .= (empty($option) ? '' : '_') . 'nopayment';
     $filter[] = 'nopayment';
     print 'Rebuild PDF for invoices with no payment done yet.' . "\n";
 }
 if ($value == 'filter=bank') {
     $found = true;
     $option .= (empty($option) ? '' : '_') . 'bank_' . $argv[$key + 1];
/**
 * Create an invoice
 *
 * @param	array		$authentication		Array of authentication information
 * @param	Facture		$invoice			Invoice
 * @return	array							Array result
 */
function createInvoice($authentication, $invoice)
{
    global $db, $conf, $langs;
    $now = dol_now();
    dol_syslog("Function: createInvoiceForThirdParty login=" . $authentication['login']);
    if ($authentication['entity']) {
        $conf->entity = $authentication['entity'];
    }
    // Init and check authentication
    $objectresp = array();
    $errorcode = '';
    $errorlabel = '';
    $error = 0;
    $fuser = check_authentication($authentication, $error, $errorcode, $errorlabel);
    if (!$error) {
        $newobject = new Facture($db);
        $newobject->socid = $invoice['thirdparty_id'];
        $newobject->type = $invoice['type'];
        $newobject->ref_ext = $invoice['ref_ext'];
        $newobject->date = dol_stringtotime($invoice['date'], 'dayrfc');
        $newobject->note_private = $invoice['note_private'];
        $newobject->note_public = $invoice['note_public'];
        $newobject->statut = 0;
        // We start with status draft
        $newobject->fk_project = $invoice['project_id'];
        $newobject->date_creation = $now;
        // Trick because nusoap does not store data with same structure if there is one or several lines
        $arrayoflines = array();
        if (isset($invoice['lines']['line'][0])) {
            $arrayoflines = $invoice['lines']['line'];
        } else {
            $arrayoflines = $invoice['lines'];
        }
        foreach ($arrayoflines as $key => $line) {
            // $key can be 'line' or '0','1',...
            $newline = new FactureLigne($db);
            $newline->product_type = $line['type'];
            $newline->desc = $line['desc'];
            $newline->fk_product = $line['fk_product'];
            $newline->tva_tx = $line['vat_rate'];
            $newline->qty = $line['qty'];
            $newline->subprice = $line['unitprice'];
            $newline->total_ht = $line['total_net'];
            $newline->total_tva = $line['total_vat'];
            $newline->total_ttc = $line['total'];
            $newline->date_start = dol_stringtotime($line['date_start']);
            $newline->date_end = dol_stringtotime($line['date_end']);
            $newline->fk_product = $line['product_id'];
            $newobject->lines[] = $newline;
        }
        //var_dump($newobject->date_lim_reglement); exit;
        //var_dump($invoice['lines'][0]['type']);
        $db->begin();
        $result = $newobject->create($fuser, 0, dol_stringtotime($invoice['date_due'], 'dayrfc'));
        if ($result < 0) {
            $error++;
        }
        if ($invoice['status'] == 1) {
            $result = $newobject->validate($fuser);
            if ($result < 0) {
                $error++;
            }
        }
        if (!$error) {
            $db->commit();
            $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref);
        } else {
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $newobject->error;
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}
Esempio n. 11
0
		$option.=(empty($option)?'':'_').'date_'.$argv[$key+1].'_'.$argv[$key+2];
		$filter[]='date';

		$dateafterdate=dol_stringtotime($argv[$key+1]);
		$datebeforedate=dol_stringtotime($argv[$key+2]);
		print 'Rebuild PDF for invoices validated between '.dol_print_date($dateafterdate,'day')." and ".dol_print_date($datebeforedate,'day').".\n";
	}

	if ($value == 'filter=payments')
	{
		$found=true;
		$option.=(empty($option)?'':'_').'payments_'.$argv[$key+1].'_'.$argv[$key+2];
		$filter[]='payments';

		$paymentdateafter=dol_stringtotime($argv[$key+1]);
		$paymentdatebefore=dol_stringtotime($argv[$key+2]);
		print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day')." and ".dol_print_date($paymentdatebefore,'day').".\n";
	}

	if ($value == 'filter=nopayment')
	{
		$found=true;
		$option.=(empty($option)?'':'_').'nopayment';
		$filter[]='nopayment';

		print 'Rebuild PDF for invoices with no payment done yet.'."\n";
	}

    if ($value == 'filter=nodeposit')
    {
        $found=true;
Esempio n. 12
0
    /**
     * testDolStringToTime
     *
     * @return int
     */
    public function testDolStringToTime()
    {
        global $conf,$user,$langs,$db;
        $conf=$this->savconf;
        $user=$this->savuser;
        $langs=$this->savlangs;
        $db=$this->savdb;

        $stime='1970-01-01T02:00:00Z';
        $result=dol_stringtotime($stime);
    	print __METHOD__." result=".$result."\n";
		$this->assertEquals(7200,$result);

        $stime='19700101T020000Z';
        $result=dol_stringtotime($stime);
    	print __METHOD__." result=".$result."\n";
		$this->assertEquals(7200,$result);

		$stime='19700101020000';
		$result=dol_stringtotime($stime);
		print __METHOD__." result=".$result."\n";
		$this->assertEquals(7200,$result);

		$stime='19700101';
		$result=dol_stringtotime($stime);
		print __METHOD__." result=".$result."\n";
		$this->assertEquals(0,$result);

        return $result;
    }
Esempio n. 13
0
if (! empty($conf->commande->enabled)) 	    $langs->load("orders");
if (! empty($conf->propal->enabled))   	    $langs->load("propal");
if (! empty($conf->ficheinter->enabled))	$langs->load("interventions");
if (! empty($conf->deplacement->enabled))	$langs->load("trips");
if (! empty($conf->expensereport->enabled)) $langs->load("trips");
if (! empty($conf->don->enabled))			$langs->load("donations");

$id=GETPOST('id','int');
$ref=GETPOST('ref','alpha');
$action=GETPOST('action','alpha');
$datesrfc=GETPOST('datesrfc');
$dateerfc=GETPOST('dateerfc');
$dates=dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
$datee=dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
if (empty($dates) && ! empty($datesrfc)) $dates=dol_stringtotime($datesrfc);
if (empty($datee) && ! empty($dateerfc)) $datee=dol_stringtotime($dateerfc);
if (! isset($_POST['datesrfc']) && ! isset($_POST['datesday']) && ! empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR))
{
	$new=dol_now();
	$tmp=dol_getdate($new);
	//$datee=$now
	//$dates=dol_time_plus_duree($datee, -1, 'y');
	$dates=dol_get_first_day($tmp['year'],1);
}
if ($id == '' && $projectid == '' && $ref == '')
{
	dol_print_error('','Bad parameter');
	exit;
}

$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
    }
    print '</td></tr>' . "\n";
}
// Client
$var = !$var;
$tz = (int) $_SESSION['dol_tz'] + (int) $_SESSION['dol_dst'];
print '<tr ' . $bc[$var] . '><td width="300">' . $langs->trans("ClientTZ") . '</td><td>' . ($tz ? ($tz >= 0 ? '+' : '') . $tz : '') . ' (' . ($tz >= 0 ? '+' : '') . $tz * 60 * 60 . ')';
print ' &nbsp; &nbsp; &nbsp; ' . $_SESSION['dol_tz_string'];
print ' &nbsp; &nbsp; &nbsp; ' . $langs->trans("DaylingSavingTime") . ': ';
if ($_SESSION['dol_dst'] > 0) {
    print yn(1);
} else {
    print yn(0);
}
if (!empty($_SESSION['dol_dst_first'])) {
    print ' &nbsp; &nbsp; (' . dol_print_date(dol_stringtotime($_SESSION['dol_dst_first']), 'dayhour', 'gmt') . ' - ' . dol_print_date(dol_stringtotime($_SESSION['dol_dst_second']), 'dayhour', 'gmt') . ')';
}
print '</td></tr>' . "\n";
print '</td></tr>' . "\n";
$var = !$var;
print '<tr ' . $bc[$var] . '><td width="300">&nbsp; => ' . $langs->trans("ClientHour") . '</td><td>' . dol_print_date(dol_now(), 'dayhour', 'tzuser') . '</td></tr>' . "\n";
$var = !$var;
$filesystemencoding = ini_get("unicode.filesystem_encoding");
// Disponible avec PHP 6.0
print '<tr ' . $bc[$var] . '><td width="300">' . $langs->trans("File encoding") . ' (php.ini unicode.filesystem_encoding)</td><td>' . $filesystemencoding . '</td></tr>' . "\n";
// date.timezone must be in valued defined in http://fr3.php.net/manual/en/timezones.europe.php
$var = !$var;
$tmp = ini_get("unicode.filesystem_encoding");
// Disponible avec PHP 6.0
if (empty($tmp) && !empty($_SERVER["WINDIR"])) {
    $tmp = 'iso-8859-1';
Esempio n. 15
0
 }
 print '<tr><td width="30%" class="nowrap"><span class="fieldrequired">' . $langs->trans("DateActionStart") . '</span></td><td>';
 if (GETPOST("afaire") == 1) {
     $form->select_date($datep, 'ap', 1, 1, 0, "action", 1, 1, 0, 0, 'fulldayend');
 } else {
     if (GETPOST("afaire") == 2) {
         $form->select_date($datep, 'ap', 1, 1, 1, "action", 1, 1, 0, 0, 'fulldayend');
     } else {
         $form->select_date($datep, 'ap', 1, 1, 1, "action", 1, 1, 0, 0, 'fulldaystart');
     }
 }
 print '</td></tr>';
 // Date end
 $datef = $datef ? $datef : $object->datef;
 if (GETPOST('datef', 'int', 1)) {
     $datef = dol_stringtotime(GETPOST('datef', 'int', 1), 0);
 }
 if (empty($datef) && !empty($datep) && !empty($conf->global->AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS)) {
     $datef = dol_time_plus_duree($datep, $conf->global->AGENDA_AUTOSET_END_DATE_WITH_DELTA_HOURS, 'h');
 }
 print '<tr><td><span id="dateend"' . (GETPOST("actioncode") == 'AC_RDV' ? ' class="fieldrequired"' : '') . '>' . $langs->trans("DateActionEnd") . '</span></td><td>';
 if (GETPOST("afaire") == 1) {
     $form->select_date($datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 0, 'fulldayend');
 } else {
     if (GETPOST("afaire") == 2) {
         $form->select_date($datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 0, 'fulldayend');
     } else {
         $form->select_date($datef, 'p2', 1, 1, 1, "action", 1, 1, 0, 0, 'fulldayend');
     }
 }
 print '</td></tr>';
     $error++;
     print ' --> ' . $member->error;
 }
 print "\n";
 //print_r($member);
 $datefirst = '';
 if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE) {
     $datefirst = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE]);
     $pricefirst = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT]);
 }
 $datelast = '';
 if ($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE) {
     $datelast = dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE]);
     $pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
 } elseif ($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) {
     $datelast = dol_time_plus_duree(dol_stringtotime($ldapuser[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION]), -1, 'y') + 60 * 60 * 24;
     $pricelast = price2num($ldapuser[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT]);
     // Cas special ou date derniere <= date premiere
     if ($datefirst && $datelast && $datelast <= $datefirst) {
         // On ne va inserer que la premiere
         $datelast = 0;
         if (!$pricefirst && $pricelast) {
             $pricefirst = $pricelast;
         }
     }
 }
 // Insert first subscription
 if ($datefirst) {
     // Cree premiere cotisation et met a jour datefin dans adherent
     //print "xx".$datefirst."\n";
     $crowid = $member->cotisation($datefirst, $pricefirst, 0);
Esempio n. 17
0
/**
 * Return server timezone int.
 * If $conf->global->MAIN_OLD_DATE is set or PHP too old, we use old behaviour: All convertions does not take care of dayling saving time.
 *
 * @param	string	$refgmtdate		Reference period for timezone (timezone differs on winter and summer. May be 'now', 'winter' or 'summer')
 * @return 	int						An offset in hour (+1 for Europe/Paris on winter and +2 for Europe/Paris on summer)
 */
function getServerTimeZoneInt($refgmtdate = 'now')
{
    global $conf;
    if (method_exists('DateTimeZone', 'getOffset') && empty($conf->global->MAIN_OLD_DATE)) {
        // Method 1 (include daylight)
        $gmtnow = dol_now('gmt');
        $yearref = dol_print_date($gmtnow, '%Y');
        $monthref = dol_print_date($gmtnow, '%m');
        $dayref = dol_print_date($gmtnow, '%d');
        if ($refgmtdate == 'now') {
            $newrefgmtdate = $yearref . '-' . $monthref . '-' . $dayref;
        } elseif ($refgmtdate == 'summer') {
            $newrefgmtdate = $yearref . '-05-15';
        } else {
            $newrefgmtdate = $yearref . '-01-01';
        }
        $localtz = new DateTimeZone(getServerTimeZoneString());
        $localdt = new DateTime($newrefgmtdate, $localtz);
        $tmp = -1 * $localtz->getOffset($localdt);
        //print $refgmtdate.'='.$tmp;
    } else {
        // Method 2 (does not include daylight, not supported by adodb)
        if ($refgmtdate == 'now') {
            if (ini_get("date.timezone") == 'UTC') {
                return 0;
            }
            // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client. Fix is to use new PHP with not MAIN_OLD_DATE.
            $gmtnow = dol_now('gmt');
            $yearref = dol_print_date($gmtnow, '%Y');
            $monthref = dol_print_date($gmtnow, '%m');
            $dayref = dol_print_date($gmtnow, '%d');
            if (dol_stringtotime($_SESSION['dol_dst_first']) <= $gmtnow && $gmtnow < dol_stringtotime($_SESSION['dol_dst_second'])) {
                $daylight = 1;
            } else {
                $daylight = 0;
            }
            $tmp = dol_mktime(0, 0, 0, $monthref, $dayref, $yearref, false, 0) - dol_mktime(0, 0, 0, $monthref, $dayref, $yearref, true, 0) - $daylight * 3600;
            return 'unknown';
            // For true result
        } elseif ($refgmtdate == 'summer') {
            if (ini_get("date.timezone") == 'UTC') {
                return 0;
            }
            // We don't know server timezone string, so we don't know location, so we can't guess daylight. We assume we use same than client. Fix is to use new PHP with not MAIN_OLD_DATE.
            $gmtnow = dol_now('gmt');
            $yearref = dol_print_date($gmtnow, '%Y');
            $monthref = '08';
            $dayref = '01';
            if (dol_stringtotime($_SESSION['dol_dst_first']) <= dol_stringtotime($yearref . '-' . $monthref . '-' . $dayref) && dol_stringtotime($yearref . '-' . $monthref . '-' . $dayref) < dol_stringtotime($_SESSION['dol_dst_second'])) {
                $daylight = 1;
            } else {
                $daylight = 0;
            }
            $tmp = dol_mktime(0, 0, 0, $monthref, $dayref, $yearref, false, 0) - dol_mktime(0, 0, 0, $monthref, $dayref, $yearref, true, 0) - $daylight * 3600;
            return 'unknown';
            // For true result
        } else {
            $tmp = dol_mktime(0, 0, 0, 1, 1, 1970);
        }
    }
    $tz = round(($tmp < 0 ? 1 : -1) * abs($tmp / 3600));
    return $tz;
}
Esempio n. 18
0
/**
 * Create order
 *
 * @param	array		$authentication		Array of authentication information
 * @param	array		$order				Order info
 * @return	int								Id of new order
 */
function createOrder($authentication, $order)
{
    global $db, $conf, $langs;
    require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php';
    $now = dol_now();
    dol_syslog("Function: createOrder login="******" socid :" . $order['socid']);
    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) {
        $newobject = new Commande($db);
        $newobject->socid = $order['thirdparty_id'];
        $newobject->type = $order['type'];
        $newobject->ref_ext = $order['ref_ext'];
        $newobject->date = dol_stringtotime($order['date'], 'dayrfc');
        $newobject->date_lim_reglement = dol_stringtotime($order['date_due'], 'dayrfc');
        $newobject->note_private = $order['note_private'];
        $newobject->note_public = $order['note_public'];
        $newobject->statut = 0;
        // We start with status draft
        $newobject->billed = $order['billed'];
        $newobject->fk_project = $order['project_id'];
        $newobject->fk_delivery_address = $order['fk_delivery_address'];
        $newobject->cond_reglement_id = $order['cond_reglement_id'];
        $newobject->demand_reason_id = $order['demand_reason_id'];
        $newobject->date_creation = $now;
        // Retrieve all extrafield for order
        // fetch optionals attributes and labels
        $extrafields = new ExtraFields($db);
        $extralabels = $extrafields->fetch_name_optionals_label('commandet', true);
        foreach ($extrafields->attribute_label as $key => $label) {
            $key = 'options_' . $key;
            $newobject->array_options[$key] = $order[$key];
        }
        // Trick because nusoap does not store data with same structure if there is one or several lines
        $arrayoflines = array();
        if (isset($order['lines']['line'][0])) {
            $arrayoflines = $order['lines']['line'];
        } else {
            $arrayoflines = $order['lines'];
        }
        foreach ($arrayoflines as $key => $line) {
            // $key can be 'line' or '0','1',...
            $newline = new OrderLine($db);
            $newline->type = $line['type'];
            $newline->desc = $line['desc'];
            $newline->fk_product = $line['product_id'];
            $newline->tva_tx = $line['vat_rate'];
            $newline->qty = $line['qty'];
            $newline->price = $line['price'];
            $newline->subprice = $line['unitprice'];
            $newline->total_ht = $line['total_net'];
            $newline->total_tva = $line['total_vat'];
            $newline->total_ttc = $line['total'];
            $newline->date_start = $line['date_start'];
            $newline->date_end = $line['date_end'];
            // Retrieve all extrafield for lines
            // fetch optionals attributes and labels
            $extrafields = new ExtraFields($db);
            $extralabels = $extrafields->fetch_name_optionals_label('commandedet', true);
            foreach ($extrafields->attribute_label as $key => $label) {
                $key = 'options_' . $key;
                $newline->array_options[$key] = $line[$key];
            }
            $newobject->lines[] = $newline;
        }
        $db->begin();
        dol_syslog("Webservice server_order:: order creation start", LOG_DEBUG);
        $result = $newobject->create($fuser);
        dol_syslog('Webservice server_order:: order creation done with $result=' . $result, LOG_DEBUG);
        if ($result < 0) {
            dol_syslog("Webservice server_order:: order creation failed", LOG_ERR);
            $error++;
        }
        if ($order['status'] == 1) {
            dol_syslog("Webservice server_order:: order validation start", LOG_DEBUG);
            $result = $newobject->valid($fuser);
            if ($result < 0) {
                dol_syslog("Webservice server_order:: order validation failed", LOG_ERR);
                $error++;
            }
        }
        if ($result >= 0) {
            dol_syslog("Webservice server_order:: order creation & validation succeeded, commit", LOG_DEBUG);
            $db->commit();
            $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref);
        } else {
            dol_syslog("Webservice server_order:: order creation or validation failed, rollback", LOG_ERR);
            $db->rollback();
            $error++;
            $errorcode = 'KO';
            $errorlabel = $newobject->error;
        }
    }
    if ($error) {
        $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel));
    }
    return $objectresp;
}