bebeboutik/modules/philea_magistor/script/recept_preparation.php
2016-09-06 15:32:52 +02:00

128 lines
3.6 KiB
PHP

<?php
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bricoprive.com';
include('../../../config/settings.inc.php');
include('../../../config/config.inc.php');
@ini_set('display_errors', 'on');
include( dirname(__FILE__) . '/../philea_magistor.php');
global $regex_file_in;
$regex_file_in = '@^CRP(.*)\.(BAL|DAT)@';
$magistorModule = new philea_magistor();
$CRP = array(
'OP_CODE' => array(1,10),
'CODE_SOC' => array(11,20),
'N_CDE' => array(31,50),
'NO_CLIENT' => array(81,8), // NO_VENTE
'DATE_PREP' => array(89,8),
'NO_LIGNE' => array(97,4),
'NO_COLIS' => array(101,50), // N_CDE
'CODE_ART' => array(151,50),
'QTE' => array(201,10)
);
$format = $CRP;
if($magistorModule->active) {
require_once('connection_ftp.php');
@set_time_limit(0);
// Checking for ".bal" files with a "CRP" prefix that has an equivalent ".dat" file and process them...
$inFolder = dirname(__FILE__) . '/IN/';
$iterator = new DirectoryIterator($inFolder);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile()) {
if( preg_match( '@^CRP(.*)\.BAL@', $fileinfo->getFilename() ) ) {
$datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() );
if( file_exists( $datFile ) ) {
$content = file_get_contents( $datFile );
$lines = preg_split( '@\n@', $content );
// ANTADIS
if( !empty($lines) ) {
foreach( $lines as $line ) {
// $data = array();
// foreach($format as $field => $value) {
// $data[] = substr($line, ($value[0]-1), $value[1]);
// }
// if( !isset($data[2]) || (isset($data[2]) && !$data[2]) )
// continue;
// // UPDATE SUPPLIER_ORDER
// // GET ORDER
// $order = (string) trim($data[2]);
// if(substr($order, 0, 2) == 'OP') {
// $order = explode('-', $order);
// if(count($order) < 2)
// continue;
// $id_sale = (int) str_replace('OP', '', $order[0]);
// $id_order = (int) $order[1];
// } else {
// $id_order = (int) $order;
// }
// // GET PRODUCT
// $product = trim($data[7]);
// $product = explode('_', $product);
// $id_product = (int) $product[0];
// $id_product_attribute = (isset($product[1]) ? (int) $product[1] : 0);
// // GET QTY
// if (!isset($data[8]) || !$data[8])
// continue;
// $qty = (int) trim($data[8]);
// if (!$qty)
// continue;
// $id_order_form = Db::getInstance()->getValue('
// SELECT `id_order_form`
// FROM `' . _DB_PREFIX_ . 'supplier_order`
// WHERE `id_sale` = ' . (int) $id_sale);
// if (!$id_order_form)
// continue;
// $update_sql = '
// UPDATE `' . _DB_PREFIX_ . 'supplier_order_detail`
// SET `quantity_accepted` = `quantity_accepted` + ' . (int)$qty . '
// WHERE `id_order_form` = ' . (int) $id_order_form . '
// AND `id_product` = ' . (int) $id_product . '
// AND `id_product_attribute` = ' . (int) $id_product_attribute . '
// LIMIT 1';
// Db::getInstance()->execute($update_sql);
}
}
$repo_archive = './archives/IN/PREPARATION/';
$repo_paths = array(date('Y'), date('m'));
foreach ($repo_paths as $repo_path) {
$repo_archive .= $repo_path . '/';
if (!file_exists($repo_archive))
mkdir($repo_archive);
}
copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ));
unlink($inFolder.$fileinfo->getFilename());
unlink($datFile);
}
}
}
}
}