Commit a3a94429 authored by Danny Froberg's avatar Danny Froberg 💬
Browse files

Initial

parent 86fb05c1
# IntelliJ project files
.idea
.idea/
\ No newline at end of file
<?php
$field_len = 0+(mb_strlen( "\r\n"));
$field_head = Array("Faltnamn","Beskrivning","Startpos","Langd","Dec","Datatyp");
$field_desc = Array(
Array('BOLNR','Leverantörens idnummer hos Finfo','1','10',' ','AN'),
Array('BOARTL','Leverantörens artikelnummer 1','11','18',' ','AN'),
Array('BOEART','Leverantörens ersättningsartikelnummer','29','18',' ','AN'),
Array('BOARTS','Finfos artikelnummer 1','47','9','0','N'),
Array('BORESERV','Reserverat fält för framtida bruk 1','56','7',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 2','63','11','0','N'),
Array('BORESERV','Reserverat fält för framtida bruk 3','74','8','0','N'),
Array('BOLBN1','Leverantörs benämning rad 1','82','30',' ','AN'),
Array('BOLBN2','Leverantörs benämning rad 2','112','30',' ','AN'),
Array('BOBNL1','Finfos benämning rad 1','142','30',' ','AN'),
Array('BOBNL2','Finfos benämning rad 2','172','30',' ','AN'),
Array('BOBENS','Finfos artikelnummer 2','202','20',' ','AN'),
Array('BOSOKL1','Leverantörens sökord 1','222','20',' ','AN'),
Array('BOSOKL2','Leverantörens sökord 2','242','20',' ','AN'),
Array('BOSOKL3','Leverantörens sökord 3','262','20',' ','AN'),
Array('BOVARUM','Varumärke','282','20',' ','AN'),
Array('BOSOKL5','Leverantörens artikelnummer 2','302','20',' ','AN'),
Array('BOPRIS','Baspris','322','10','2','N'),
Array('BOENH','Basprisenhet','332','3',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 4','335','2','0','AN'),
Array('BOPC1','Försäljningspris (ca-pris)','337','10','2','N'),
Array('BORESERV','Reserverat fält för framtida bruk 5','347','3',' ','AN'),
Array('BOJIFA','Jämförprisfaktor','350','11','6','N'),
Array('BOENHJ','Jämförprisenhet','361','3',' ','AN'),
Array('BOUDA','Prisgällandedatum för baspriset','364','8','0','N'),
Array('BOPRPR','Pris per','372','5','0','N'),
Array('BONETPR','Nettopris','377','10','2','N'),
Array('BONPRUDA','Gällandedatum kundunikt nettopris','387','8','0','N'),
Array('BOBRUPR','Kundunikt försäljningspris','395','10','2','N'),
Array('BOBPRUDA','Gällandedatum kundunikt försäljningspris','405','8','0','N'),
Array('BOPRTBASF','Faktor Basprisenhet/Primärförpackningsenhet','413','11','6','N'),
Array('BOPRIENH','Primärförpackningens enhet','424','3',' ','AN'),
Array('BOSEKTPRF','Faktor primär-/sekundärenhet','427','11','6','N'),
Array('BOSEKENH','Sekundärförpackningsenhet','438','3',' ','AN'),
Array('BOTERTPRF','Faktor primär-/tertiärenhet','441','11','6','N'),
Array('BOTERENH','Tertiärförpackningens enhet','452','3',' ','AN'),
Array('BOPRIINH','Primärförpackningens innehåll','455','9','3','N'),
Array('BOENHPRI','Enhet för primärförpackningens innehåll','464','3',' ','AN'),
Array('BOPREAN','Primärförpackningens GTIN','467','14',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 6','481','6','1','N'),
Array('BORESERV','Reserverat fält för framtida bruk 7','487','6','1','N'),
Array('BORESERV','Reserverat fält för framtida bruk 8','493','6','1','N'),
Array('BORESERV','Reserverat fält för framtida bruk 9','499','9','3','N'),
Array('BOPRIVOL','Reserverat fält för framtida bruk 10','508','9','3','N'),
Array('BOPRFBEIN','Primärförpackningens beställningsindikator','517','1',' ','AN'),
Array('BOSEKINH','Sekundärförpackningens innehåll','518','9','3','N'),
Array('BOENHSEK','Enhet för sekundärförpackningens innehåll','527','3',' ','AN'),
Array('BOSEFBEIN','Sekundärförpackningens beställningsindikator','530','1',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 11','531','20',' ','AN'),
Array('BOSEEAN','Sekundärförpackningens GTIN','551','14',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 12','565','9','3','N'),
Array('BORESERV','Reserverat fält för framtida bruk 13','574','3',' ','AN'),
Array('BOTEEAN','Tertiärförpackningens GTIN','577','14',' ','AN'),
Array('BOBRAVG','Varugrupp BK04','591','5',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 14','596','8',' ','AN'),
Array('BORABGR','Rabattgrupp','604','10',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 15','614','30',' ','AN'),
Array('BOPGRP','Prisgrupp','644','3',' ','AN'),
Array('BOKALGR','Kalkylgrupp','647','5',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 16','652','30',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 17','682','10',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 18','692','5',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 19','697','8','0','N'),
Array('BOUTGKOD','Artikelns utgåendekod','705','2','0','N'),
Array('BOUTGD','Utgåendedatum','707','8','0','N'),
Array('BOLTYP','Kod lager/beställningsvara eller tillverkning','715','1',' ','AN'),
Array('BORESERV','Reserverat fält för framtida bruk 20','716','2','0','N'),
);
<?php
/**
* BoList File Parser
*/
require_once "includes/definitions.php";
/**
* @param $field_head
* @param $field_desc
*
* @return string
*/
function bulid_field_desc($field_head,$field_desc) {
global $field_len;
$fi = 0;
foreach ($field_desc as $key) {
switch($key[5]) {
case 'AN': $datatype = 'A'; break;
case 'N' : $datatype = 'A'; break;
}
$field = $key[0];
if ($field == 'BORESERV') {
$fi++;
$field .= $fi;
}
$descriptor[] = $datatype.$key[3].$field;
$field_len += $key[3];
}
// var_dump( $descriptor );
return implode( '/', $descriptor);
}
function get_descriptor_details( $field ) {
global $field_desc;
return $field_desc[0][array_search( $field, $field_desc)];
}
function myEncodeFunction(&$item)
{
$item = mb_convert_encoding($item, 'UTF-8', 'CP850');
}
function make_price($number,$decimals = 2) {
if($decimals > 0) {
return number_format( substr_replace( $number, '.', mb_strlen( $number ) - $decimals, 0 ), $decimals, ',', ' ' );
} else {
return number_format( $number, $decimals, ',', '' );
}
}
/**
* @param $fields
*/
function process_fields( $fields ) {
global $field_desc;
$i = 0;
echo $fields['BOPREAN'] . "\t" . $fields['BOARTL'] . "\t" . $fields['BOBNL1'] . "\t" .$fields['BOBNL2'] . "\t" . make_price($fields['BOPRIS'],2)."\t" . $fields['BOENH'] ."\t".make_price($fields['BOPC1'])."\n";
}
function parse() {
global $field_head, $field_desc, $field_len;
// Build Head
$descriptor = bulid_field_desc( $field_head, $field_desc );
// Read in file
$file_name = './tests/aaa_readfile.txt';
$file_size = filesize( $file_name );
$file_desc = fopen( $file_name,'rb' ) or die ("can't open file");
$buffer = fread( $file_desc, $file_size );
$chunks = str_split($buffer, $field_len);
$i = 1;
foreach ($chunks as $lines) {
// $buffer_conv = mb_convert_encoding($lines,'auto', 'CP850');
$line = unpack( $descriptor, $lines );
array_walk_recursive($line, 'myEncodeFunction');
if ( ! $line ) {
echo "\nError:\n";
var_dump( $descriptor );
//var_dump( $buffer_conv );
var_dump( $line );
exit();
}
$fields[] = $line; //Save for later.
// var_dump( array_chunk( $line, count( $field_desc ), true ) );
echo sprintf( "%06d", $i) ."\t";
$i++;
process_fields( $line );
}
echo 'count: '.count( $field_desc )."\n";
echo 'lines: '.count( $chunks )."\n";
echo 'field len: '. $field_len."\n";
//var_dump( $fields );
fclose($file_desc) or die("can't close file");
}
// Test
parse();
\ No newline at end of file
000698069271079 007126112 0000000000000000000DECOTIQUE TAK O GOLVSKENA ALUMINIUM 1803MM SVART TAK- GOLVSKENA DECOTIQUE SVARTALUMINIUM 1803MM 7126112 71079 0000000000ST 000000000000 00001000000ST 201903220000100000000000000000000000000000000000000001000000ST 00000000000 00000000000 000001000ST 7392118710791 000000000000000000000000000000000000 000000000 000000000 04005 SKJD 000000000000000000L00
000698069271080 007126113 0000000000000000000DECOTIQUE TAK O GOLVSKENA ALUMINIUM 2692MM SVART TAK- GOLVSKENA DECOTIQUE SVARTALUMINIUM 2692MM 7126113 71080 0000135600ST 000000159600 00001000000ST 201903220000100001356002019040100000000000000000000001000000ST 00000000000 00000000000 000001000ST 7392118710807 000000000000000000000000000000000000 000000000 000000000 04005 SKJD 000000000000000000L00
000698069219056 007096221 0000000000000000000PANELSKIVA ALMA PRLSPONT 2-PACK ANTIKVIT 2390X620X6 PANELSKIVA ALMA PRLSPONT ANTIKVIT 2390X620X6 2ST 7096221 19056 0000033000PKT000000000000 00002000000ST 201903220000100000380002019040100000000000000000000001000000PKT00000000000 00000000000 000002000ST 7392118190562 000000000000000000000000000000000000 000000000 000000000 01210 PANHE 000000000000000000L00
000698069212160 003434659 0000000000000000000HATTHYLLA HALDOR OBEHANDLAD EK 300X300X310 HATTHYLLA HALDOR EK OBEHANDLAD300X300X310 3434659 12160 0000018400ST 000000000000 00001000000ST 201903220000100000184002016041200000000000000000000001000000ST 00000000000 00000000000 000001000ST 7392118121603 000000000000000000000000000000000000 000000000 000000000 06104 SHYL 000000000000000000L00
000698069218161 006059402 0000000000000000000ENTREMATTA MODENA ANTRACIT 600X900 ENTREMATTA MODENA ANTRACIT 600X900MM 6059402 18161 0000008900ST 000000000000 00001000000ST 201903220000100000089002018032100000000000000000000001000000ST 00000000000 00000000000 000001000ST 7391719181610 000000000000000000000000000000000000 000000000 000000000 03109 EMAT 000000000000000000L00
000698069281622 006995170 0000000000000000000TRAPP PREMIUM COUNTRY DUBBELST EK OLJAD 1450X590X8 TRAPP PREMIUM COUNTRY DUBBELST EK OLJAD 1450X590X8 6995170 81622 0000111900ST 000000172160 00001000000ST 201902150000100001119002019040100000000000000000000001000000ST 00002000000KRT00000000000 000001000ST 7392118816226 000000000000000000000000000000000000 000002000ST 17392118816223000000000 04402 TSTEG 000000000000000000L00
000698069281623 006995171 0000000000000000000TRAPP PREMIUM COUNTRY DUBBELST EK OLJAD 1800X590X8 TRAPP PREMIUM COUNTRY DUBBELST EK OLJAD 1800X590X8 6995171 81623 0000160800ST 000000247360 00001000000ST 201902150000100001608002019040100000000000000000000001000000ST 00002000000KRT00000000000 000001000ST 7392118816233 000000000000000000000000000000000000 000002000ST 17392118816230000000000 04402 TSTEG 000000000000000000L00
000698069271077 007030334 0000000000000000000DECOTIQUE TAK O GOLVSKENA ALUMINIUM 1803MM SILVER TAK&GOLVSKENA DECOTIQUE ALUMINIUM SILVER 1803MM 7030334 71077 0000088000ST 000000103600 00001000000ST 201903220000100001117002018121400000000000000000000001000000ST 00000000000 00000000000 000001000ST 7392118710777 000000000000000000000000000000000000 000000000 000000000 04005 SKJD 000000000000000000L00
000698069271078 007030335 0000000000000000000DECOTIQUE TAK O GOLVSKENA ALUMINIUM 2692MM SILVER TAK&GOLVSKENA DECOTIQUE ALUMINIUM SILVER 2692MM 7030335 71078 0000135600ST 000000159600 00001000000ST 201903220000100001676002018121400000000000000000000001000000ST 00000000000 00000000000 000001000ST 7392118710784 000000000000000000000000000000000000 000000000 000000000 04005 SKJD 000000000000000000L00
000698069281841 007030348 0000000000000000000TRSKEL EK LACKAD 1000X75X9 TRSKEL EK LACKAD 1000X75X9MM 7030348 81841 0000010100ST 000000015760 00001000000ST 201902150000100000101002019040100000000000000000000001000000ST 00006000000FRP00000000000 000001000ST 7392118818411 000000000000000000000000000000000000 000006000ST 17392118818418000000000 04099 TR 000000000000000000L00
000698069281842 007030349 0000000000000000000TRSKEL EK LACKAD 2000X75X9 TRSKEL EK LACKAD 2000X75X9MM 7030349 81842 0000018300ST 000000028640 00001000000ST 201902150000100000183002019040100000000000000000000001000000ST 00006000000FRP00000000000 000001000ST 7392118818428 000000000000000000000000000000000000 000006000ST 17392118818425000000000 04099 TR 000000000000000000L00
000698069281851 007030350 0000000000000000000TRSKEL EK LACKAD 1000X90X9 TRSKEL EK LACKAD 1000X90X9MM 7030350 81851 0000012300ST 000000019200 00001000000ST 201902150000100000123002019040100000000000000000000001000000ST 00006000000FRP00000000000 000001000ST 7392118818510 000000000000000000000000000000000000 000006000ST 17392118818517000000000 04099 TR 000000000000000000L00
000698069281852 007030351 0000000000000000000TRSKEL EK LACKAD 2000X90X9 TRSKEL EK LACKAD 2000X90X9MM 7030351 81852 0000025000ST 000000039200 00001000000ST 201902150000100000250002019040100000000000000000000001000000ST 00006000000FRP00000000000 000001000ST 7392118818527 000000000000000000000000000000000000 000006000ST 17392118818524000000000 04099 TR 000000000000000000L00
000698069281861 007030352 0000000000000000000TRSKEL EK LACKAD 1000X120X9 TRSKEL EK LACKAD 1000X120X9MM 7030352 81861 0000014600ST 000000022880 00001000000ST 201902150000100000146002019040100000000000000000000001000000ST 00006000000FRP00000000000 000001000ST 7392118818619 000000000000000000000000000000000000 000006000ST 17392118818616000000000 04099 TR 000000000000000000L00
000698069219050 006415941 0000000000000000000PANELSKIVA ALMA PRLSPONT ANTIKVIT 2390X620X6 PANELSKIVA ALMA PRLSPONT ANTIKVIT 2390X620X6MM 6415941 19050 0000015900ST 000000021200 00001000000ST 201902150000100000159002019040100000000000000000000001000000ST 00000000000 00000000000 000001000ST 7392118190500 000000000000000000000000000000000000 000000000 000000000 01210 PANHE 000000000420190328L00
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment