Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
documentbase.php
1<?php
3
9
16{
17 const CML_LANG_ID = 'ru';
18
20 protected $fields;
21
22 function __construct()
23 {
24 $this->fields = new Fields();
25 }
26
30 protected static function getMessage()
31 {
32 return Main\Localization\Loc::loadLanguageFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/components/bitrix/sale.export.1c/component.php', self::CML_LANG_ID);
33 }
34
38 static protected function getMessageExport()
39 {
40 return array_merge(
41 Main\Localization\Loc::loadLanguageFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/components/bitrix/sale.export.1c/component.php', self::CML_LANG_ID),
42 Main\Localization\Loc::loadLanguageFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/sale/general/export.php', self::CML_LANG_ID)
43 );
44 }
45
49 public function getTypeId()
50 {
52 }
53
58 public function setFields(array $values)
59 {
60 foreach ($values as $key=>$value)
61 {
62 $this->setField($key, $value);
63 }
64 }
65
70 public function setField($name, $value)
71 {
72 $this->fields->set($name, $value);
73 }
74
79 public function getField($name)
80 {
81 return $this->fields->get($name);
82 }
83
87 public function getFieldValues()
88 {
89 return $this->fields->getValues();
90 }
91
95 public function getId()
96 {
97 if($this->getField('ID'))
98 {
99 return $this->getField('ID');
100 }
101
102 return null;
103 }
104
108 public function getExternalId()
109 {
110 if($this->getField('ID_1C'))
111 {
112 return $this->getField('ID_1C');
113 }
114
115 return null;
116 }
117
122 public static function resolveRawDocumentTypeId(array $document)
123 {
124 $message = self::getMessage();
125 $operation = $document['#'][$message['CC_BSC1_OPERATION']][0]['#'];
126 return static::resolveDocumentTypeId($operation);
127 }
128
133 public static function resolveDocumentTypeId($operation)
134 {
135 $typeId = DocumentType::UNDEFINED;
136
137 $message = self::getMessage();
138
139 if(!empty($operation))
140 {
141 if($operation == $message["CC_BSC1_ORDER"])
142 {
143 $typeId = DocumentType::ORDER;
144 }
145 elseif($operation == $message["CC_BSC1_PAYMENT_C"])
146 {
148 }
149 elseif($operation == $message["CC_BSC1_PAYMENT_B"])
150 {
152 }
153 elseif($operation == $message["CC_BSC1_PAYMENT_A"])
154 {
156 }
157 elseif($operation == $message["CC_BSC1_SHIPMENT"])
158 {
159 $typeId = DocumentType::SHIPMENT;
160 }
161 else
162 $typeId = DocumentType::UNDEFINED;
163 }
164
165 return $typeId;
166 }
167
168 public static function resolveDocumentTypeName($typeId)
169 {
170 if(!DocumentType::IsDefined($typeId))
171 {
173 }
174
175 $message = self::getMessage();
176
177 $name = '';
178 if($typeId == DocumentType::ORDER)
179 {
180 $name = $message["CC_BSC1_ORDER"];
181 }
182 elseif($typeId == DocumentType::PAYMENT_CASH)
183 {
184 $name = $message["CC_BSC1_PAYMENT_C"];
185 }
186 elseif($typeId == DocumentType::PAYMENT_CASH_LESS)
187 {
188 $name = $message["CC_BSC1_PAYMENT_B"];
189 }
191 {
192 $name = $message["CC_BSC1_PAYMENT_A"];
193 }
194 elseif($typeId == DocumentType::SHIPMENT)
195 {
196 $name = $message["CC_BSC1_SHIPMENT"];
197 }
198
199 return $name;
200 }
201
209 public static function resolveItemsArrayParams($value, $fieldName, array $fieldsInfo, array $document)
210 {
211 $result = null;
212
213 switch($fieldName)
214 {
215 case 'REK_VALUES':
216 $result = self::resolveTraitsParams($value, $fieldsInfo);
217 break;
218 case 'TAXES':
219 $result = self::resolveTaxParams($value, $fieldsInfo);
220 break;
221 case 'ITEM_UNIT':
222 $result = self::resolveUnitParams($value, $fieldsInfo);
223 break;
224 case 'MARKING_GROUP':
225 $result = self::resolveMarkingGroupParams($value, $fieldsInfo);
226 break;
227 case 'MARKINGS':
228 $result = self::resolveMarkingParams($value, $fieldsInfo);
229 break;
230 case 'DISCOUNTS':
231 $result = self::resolveDiscountsParams($value, $fieldsInfo);
232 break;
233 }
234 return $result;
235 }
236
242 protected static function resolveItemsParams(array $document, array $fieldsInfo)
243 {
244 $result = null;
245 $message = self::getMessage();
246
247 if (is_array($document["#"][$message["CC_BSC1_ITEMS"]][0]["#"]) &&
248 is_array($document["#"][$message["CC_BSC1_ITEMS"]][0]["#"][$message["CC_BSC1_ITEM"]]))
249 {
250 $items = $document["#"][$message["CC_BSC1_ITEMS"]][0]["#"][$message["CC_BSC1_ITEM"]];
251
252 foreach ($items as $val)
253 {
254 $fields = array();
255 if(is_array($val))
256 {
257 foreach($fieldsInfo['FIELDS'] as $name => $info)
258 {
259 if(!empty($val["#"][$message["CC_BSC1_".$name]]))
260 {
261 if($info['TYPE'] === 'array')
262 {
263 $value = self::resolveItemsArrayParams($val, $name, $info, $document);
264 }
265 else
266 {
267 $value = $val["#"][$message["CC_BSC1_".$name]][0]["#"];
268
269 self::internalizeFields($value, $info);
270 }
271 $fields[$name] = $value;
272 }
273 }
274 }
275 $result[] = $fields;
276 }
277 }
278
279 return $result;
280 }
281
287 protected static function resolveCashBoxCheksParams(array $value, array $fieldsInfo)
288 {
289 $result = null;
290 $message = self::getMessage();
291
292 if (isset($value["#"][$message["CC_BSC1_CASHBOX_CHECKS"]][0]["#"][$message["CC_BSC1_CASHBOX_CHECK"]][0]['#'])
293 && !empty($value["#"][$message["CC_BSC1_CASHBOX_CHECKS"]][0]["#"][$message["CC_BSC1_CASHBOX_CHECK"]][0]['#']))
294 {
295 $properties = array();
296 $val = $value["#"][$message["CC_BSC1_CASHBOX_CHECKS"]][0]["#"][$message["CC_BSC1_CASHBOX_CHECK"]][0];
297
298 $id = $val["#"][$message["CC_BSC1_ID"]][0]["#"];
299 self::internalizeFields($id, $fieldsInfo);
300 $result['ID'] = $id;
301
302 if (isset($val["#"][$message["CC_BSC1_PROPERTY_VALUES"]][0]["#"][$message["CC_BSC1_PROPERTY_VALUE"]]) &&
303 isset($val["#"][$message["CC_BSC1_PROPERTY_VALUES"]][0]["#"][$message["CC_BSC1_PROPERTY_VALUE"]][0]['#']) &&
304 !empty($val["#"][$message["CC_BSC1_PROPERTY_VALUES"]][0]["#"][$message["CC_BSC1_PROPERTY_VALUE"]][0]['#']))
305 {
306 foreach($val["#"][$message["CC_BSC1_PROPERTY_VALUES"]][0]["#"][$message["CC_BSC1_PROPERTY_VALUE"]] as $property)
307 {
308 $propertyName = $property["#"][$message["CC_BSC1_ID"]][0]["#"];
309 $propertyValue = $property["#"][$message["CC_BSC1_VALUE"]][0]["#"];
310 if($propertyValue <> '')
311 $properties[$propertyName] = $propertyValue;
312 }
313 }
314
315 foreach($fieldsInfo['PROPERTIES']['FIELDS'] as $name => $fieldInfo)
316 {
317 if(!empty($properties[$message["CC_BSC1_".$name]]))
318 {
319 $fieldValue = $properties[$message["CC_BSC1_".$name]];
320
321 self::internalizeFields($fieldValue, $fieldInfo);
322
323 $result[$name] = $fieldValue;
324 }
325 }
326
327 return $result;
328 }
329 }
330
336 protected static function resolveTraitsParams(array $value, array $fieldsInfo)
337 {
338 $result = null;
339 $message = self::getMessage();
340
341 if (is_array($value["#"][$message["CC_BSC1_REK_VALUES"]][0]["#"][$message["CC_BSC1_REK_VALUE"]])
342 && !empty($value["#"][$message["CC_BSC1_REK_VALUES"]][0]["#"][$message["CC_BSC1_REK_VALUE"]]))
343 {
344 $traits = array();
345 foreach($value["#"][$message["CC_BSC1_REK_VALUES"]][0]["#"][$message["CC_BSC1_REK_VALUE"]] as $val)
346 {
347 $traitName = $val["#"][$message["CC_BSC1_NAME"]][0]["#"];
348 $traitValue = $val["#"][$message["CC_BSC1_VALUE"]][0]["#"];
349 if($traitValue <> '')
350 $traits[$traitName] = $traitValue;
351 }
352
353 foreach($fieldsInfo['FIELDS'] as $name => $fieldInfo)
354 {
355 $fieldValue = '';
356 if($name == 'PROPERTY_VALUE_BASKET')
357 {
358 foreach($traits as $k=>$v)
359 {
360 $namePropertyBaslet = $message["CC_BSC1_PROP_BASKET"];
361 if (mb_strpos($k, $namePropertyBaslet."#") === 0)
362 {
363 $position = mb_strpos($k, $namePropertyBaslet."#");
364 $idBasketProperty = mb_substr($k, $position + mb_strlen($namePropertyBaslet."#"));
365
367
368 $result['PROP_BASKET'][$idBasketProperty] = $v; //TODO: check && fix
369 }
370 }
371 }
372 elseif($name == 'TYPE_OF_NOMENKLATURA')
373 {
374 if($traits[$message["CC_BSC1_ITEM_TYPE"]] == $message["CC_BSC1_ITEM"])
375 $fieldValue = Exchange\ImportBase::ITEM_ITEM;
376 elseif($traits[$message["CC_BSC1_ITEM_TYPE"]] == $message["CC_BSC1_SERVICE"])
377 $fieldValue = Exchange\ImportBase::ITEM_SERVICE;
378
379 self::internalizeFields($fieldValue, $fieldInfo['FIELDS']['VALUE']);
380
381 $result['ITEM_TYPE'] = $fieldValue; //TODO: check && fix
382 }
383 elseif(!empty($traits[$message["CC_BSC1_".$name]]))
384 {
385 $fieldValue = $traits[$message["CC_BSC1_".$name]];
386
387 self::internalizeFields($fieldValue, $fieldInfo['FIELDS']['VALUE']);
388
389 $result[$name] = $fieldValue; //TODO: check && fix
390 }
391 }
392 }
393 return $result;
394 }
395
401 protected static function resolveTaxParams(array $value, array $fieldsInfo)
402 {
403 $result = null;
404 $message = self::getMessage();
405
406 if (is_array($value["#"][$message["CC_BSC1_TAXES"]][0]["#"][$message["CC_BSC1_TAX"]])
407 && !empty($value["#"][$message["CC_BSC1_TAXES"]][0]["#"][$message["CC_BSC1_TAX"]]))
408 {
409 $field = $value["#"][$message["CC_BSC1_TAXES"]][0]["#"][$message["CC_BSC1_TAX"]];
410 foreach($fieldsInfo['FIELDS'] as $name => $info)
411 {
412 if(!empty($field[0]["#"][$message["CC_BSC1_".$name]][0]["#"]))
413 {
414 $fieldValue = $field[0]["#"][$message["CC_BSC1_".$name]][0]["#"];
415 self::internalizeFields($fieldValue, $info);
416
417 $result[$name] = $fieldValue;
418 }
419 }
420 }
421 return $result;
422 }
423
429 protected static function resolveDiscountsParams(array $value, array $fieldsInfo)
430 {
431 $result = null;
432 $message = self::getMessage();
433
434 if (is_array($value["#"][$message["CC_BSC1_DISCOUNTS"]][0]["#"][$message["CC_BSC1_DISCOUNT"]])
435 && !empty($value["#"][$message["CC_BSC1_DISCOUNTS"]][0]["#"][$message["CC_BSC1_DISCOUNT"]]))
436 {
437 $field = $value["#"][$message["CC_BSC1_DISCOUNTS"]][0]["#"][$message["CC_BSC1_DISCOUNT"]];
438 foreach($fieldsInfo['FIELDS'] as $name => $info)
439 {
440 if(!empty($field[0]["#"][$message["CC_BSC1_".$name]][0]["#"]))
441 {
442 $fieldValue = $field[0]["#"][$message["CC_BSC1_".$name]][0]["#"];
443 self::internalizeFields($fieldValue, $info);
444
445 $result[$name] = $fieldValue;
446 }
447 }
448 }
449 return $result;
450 }
451
457 protected static function resolveUnitParams($value, array $fieldsInfo)
458 {
459 $result = null;
460 $message = self::getMessage();
461
462 if (is_array($value["#"][$message["CC_BSC1_ITEM_UNIT"]])
463 && !empty($value["#"][$message["CC_BSC1_ITEM_UNIT"]]))
464 {
465 $field = $value["#"][$message["CC_BSC1_ITEM_UNIT"]];
466
467 foreach($fieldsInfo['FIELDS'] as $name => $info)
468 {
469 if(is_array($field[0]["#"]))
470 {
471 if(!empty($field[0]["#"][$message["CC_BSC1_".$name]][0]["#"]))
472 {
473 $fieldValue = $field[0]["#"][$message["CC_BSC1_".$name]][0]["#"];
474 self::internalizeFields($fieldValue, $info);
475 $result[$name] = $fieldValue;
476 }
477 }
478 else
479 {
480 $fieldValue='';
481 if($result==null)
482 {
483 $fieldValue = $field[0]["#"];
484 self::internalizeFields($fieldValue, $info);
485 }
486 $result[$name] = $fieldValue;
487 }
488 }
489 }
490 return $result;
491 }
492
498 protected static function resolveMarkingGroupParams($value, array $fieldsInfo)
499 {
500 $result = null;
501 $message = self::getMessage();
502
503 if (is_array($value["#"][$message["CC_BSC1_MARKING_GROUP"]])
504 && !empty($value["#"][$message["CC_BSC1_MARKING_GROUP"]]))
505 {
506 $field = $value["#"][$message["CC_BSC1_MARKING_GROUP"]];
507
508 foreach($fieldsInfo['FIELDS'] as $name => $info)
509 {
510 if(is_array($field[0]["#"]))
511 {
512 if(!empty($field[0]["#"][$message["CC_BSC1_MARKING_GROUP_".$name]][0]["#"]))
513 {
514 $fieldValue = $field[0]["#"][$message["CC_BSC1_MARKING_GROUP_".$name]][0]["#"];
515 self::internalizeFields($fieldValue, $info);
516 $result[$name] = $fieldValue;
517 }
518 }
519 }
520 }
521 return $result;
522 }
523
529 protected static function resolveMarkingParams(array $value, array $fieldsInfo)
530 {
531 $result = [];
532 $message = self::getMessage();
533
534 if (is_array($value["#"][$message["CC_BSC1_MARKINGS"]][0]["#"][$message["CC_BSC1_MARKING"]])
535 && !empty($value["#"][$message["CC_BSC1_MARKINGS"]][0]["#"][$message["CC_BSC1_MARKING"]]))
536 {
537 $fields = $value["#"][$message["CC_BSC1_MARKINGS"]][0]["#"][$message["CC_BSC1_MARKING"]];
538
539 foreach($fields as $k=>$field)
540 {
541 foreach($fieldsInfo['FIELDS'] as $name => $info)
542 {
543 if(!empty($field["#"][$message["CC_BSC1_MARKING_".$name]][0]["#"]))
544 {
545 $fieldValue = $field["#"][$message["CC_BSC1_MARKING_".$name]][0]["#"];
546 self::internalizeFields($fieldValue, $info);
547
548 $result[] = $fieldValue;
549 }
550 }
551 }
552
553 }
554 return $result;
555 }
556
561 protected static function fillItemsFields(array $fields)
562 {
563 $result = null;
564
565 $basketItems = array();
566 foreach($fields['ITEMS_FIELDS'] as $item)
567 {
568 $priceone = $item['PRICE_PER_UNIT'];
569 if (DoubleVal($priceone) <= 0)
570 $priceone = $item["PRICE_ONE"];
571
572
573 $discountPrice = "";
574 if (doubleval($item['QUANTITY']) > 0)
575 {
576 $price = PriceMaths::roundPrecision($item['SUMM'] / $item['QUANTITY']);
577 $priceone = PriceMaths::roundPrecision($priceone);
578
579 if(isset($item['DISCOUNTS']['SUMM']) && $item['DISCOUNTS']['SUMM']<>'')
580 {
581 if ($priceone != $price)
582 {
583 $discountPrice = DoubleVal($priceone - $price);
584 }
585 }
586 elseif ($priceone > 0)
587 {
588 $price = $priceone;
589 }
590
591 $vatRate = null;
592 if (!empty($item['TAXES']['TAX_VALUE']))
593 {
594 $taxValue = (float)$item['TAXES']['TAX_VALUE'];
595 $vatRate = $taxValue / 100;
596 }
597
598 $basketItems = Array(
599 'ID' => $item['ID'],
600 'NAME' => $item['NAME'],
601 'PRICE' => $price,
602 'PRICE_ONE' => $priceone,
603 'QUANTITY' => $item['QUANTITY'],
604 'TYPE' => $item['REK_VALUES']['ITEM_TYPE'],
605 'MEASURE_CODE' => !empty($item['ITEM_UNIT']) ? $item['ITEM_UNIT']['ITEM_UNIT_CODE']:null,
606 'MEASURE_NAME' => !empty($item['ITEM_UNIT']) ? $item['ITEM_UNIT']['ITEM_UNIT_NAME']:null,
607 'ATTRIBUTES' => !empty($item['REK_VALUES']['PROP_BASKET']) ? $item['REK_VALUES']['PROP_BASKET']:null,
608 'MARKING_GROUP' => !empty($item['MARKING_GROUP']['CODE']) ? $item['MARKING_GROUP']['CODE']:null,
609 'MARKINGS' => !empty($item['MARKINGS']) ? $item['MARKINGS']:null,
610 'TAX' => array(
611 'VAT_RATE' => $vatRate,
612 'VAT_INCLUDED' => !empty($item['TAXES']['IN_PRICE']) ? $item['TAXES']['IN_PRICE'] : 'Y'//if tax is null then always included by default
613 ),
614 'DISCOUNT' => array(
615 'PRICE' => $discountPrice
616 )
617
618 );
619 }
620 $result[][$item['ID']] = $basketItems;
621 }
622 return $result;
623 }
624
629 protected static function internalizeFields(&$value, $fieldInfo=null)
630 {
631 if($value<>'')
632 {
633 switch($fieldInfo['TYPE'])
634 {
635 case 'datetime':
636 $date = str_replace("T", " ", $value);
637 $value = new Type\DateTime(\CDatabase::FormatDate($date, "YYYY-MM-DD HH:MI:SS", \CSite::GetDateFormat("FULL", LANG)));
638 break;
639 case 'bool':
640 $value = $value == "true" ? 'Y':'N';
641 break;
642 case 'float':
643 $value = self::toFloat($value);
644 break;
645 case 'int':
646 $value = self::toInt($value);
647 break;
648 }
649 }
650 }
651
656 protected static function toFloat($value)
657 {
658 $saleOrderLoader = new \CSaleOrderLoader();
659 return $saleOrderLoader->ToFloat($value);
660 }
661
666 protected static function toInt($value)
667 {
668 $saleOrderLoader = new \CSaleOrderLoader();
669 return $saleOrderLoader->ToInt($value);
670 }
671
672
677 static public function prepareFieldsData(array $document)
678 {
679 $message = self::getMessage();
680 $fields = array();
681
682 foreach(static::getFieldsInfo() as $k=>$v)
683 {
684 switch($k)
685 {
686 case 'ID':
687 $value = $document["#"][$message["CC_BSC1_NUMBER"]][0]["#"];
688 self::internalizeFields($value, $v);
689 $fields[$k] = $value;
690 break;
691 case 'ID_1C':
692 $value = $document["#"][$message["CC_BSC1_ID"]][0]["#"];
693 self::internalizeFields($value, $v);
694 $fields[$k] = $value;
695 break;
696 case 'ORDER_ID':
697 $value = $document["#"][$message["CC_BSC1_NUMBER_BASE"]][0]["#"];
698 self::internalizeFields($value, $v);
699 $fields[$k] = $value;
700 break;
701 case 'VERSION_1C':
702 case 'COMMENT':
703 case 'CANCELED':
704 case '1C_DATE':
705 $value = $document["#"][$message["CC_BSC1_".$k]][0]["#"];
706 self::internalizeFields($value, $v);
707 $fields[$k] = $value;
708 break;
709 case '1C_TIME':
710 $date1C = $document["#"][$message["CC_BSC1_1C_DATE"]][0]["#"];
711 if($date1C >0)
712 {
713 $value = $date1C." ".$document["#"][$message["CC_BSC1_".$k]][0]["#"];
714 self::internalizeFields($value, $v);
715 $fields[$k] = $value;
716 }
717 break;
718 case 'OPERATION':
719 $typeId = self::resolveRawDocumentTypeId($document);
720 $fields[$k] = DocumentType::resolveName($typeId);
721 break;
722 case 'AMOUNT':
723 $value = $document["#"][$message["CC_BSC1_SUMM"]][0]["#"];
724 self::internalizeFields($value, $v);
725 $fields[$k] = $value;
726 break;
727 case 'CASH_BOX_CHECKS':
728 $fields[$k] = self::resolveCashBoxCheksParams($document, $v);
729 break;
730 case 'REK_VALUES':
731 $fields[$k] = self::resolveTraitsParams($document, $v);
732 break;
733 case 'ITEMS':
734 $fields['ITEMS_FIELDS'] = self::resolveItemsParams($document, $v);
735
736 if(!empty($fields['ITEMS_FIELDS']))
738 break;
739 case 'TAXES':
740 $taxValue = 0;
741 $taxName = '';
742 if(!empty($fields['ITEMS_FIELDS']))
743 {
744 foreach($fields['ITEMS_FIELDS'] as $items)
745 {
746 foreach ($items as $item)
747 {
748 $taxValueTmp = isset($item['TAX_VALUE']) ? $item['TAX_VALUE']:0;
749
750 if (intval($taxValueTmp) > intval($taxValue))
751 {
752 $taxName = $item['NAME'];
753 $taxValue = $taxValueTmp;
754 }
755 }
756 }
757 }
758
759 if(intval($taxValue)>0)
760 {
761 $fields[$k] = self::resolveTaxParams($document, $v);
762 $fields[$k]['VALUE'] = $taxValue;
763 $fields[$k]['NAME'] = $taxName;
764 }
765 break;
766 case 'AGENT':
767 /* includes document profile */
768 $documentProfile = new UserProfileDocument();
769 $mess = Main\Localization\Loc::loadLanguageFile($_SERVER["DOCUMENT_ROOT"].'/bitrix/modules/sale/general/export.php');
770
771 if(is_array($document["#"][$mess["SALE_EXPORT_CONTRAGENTS"]][0]["#"][$mess["SALE_EXPORT_CONTRAGENT"]][0]["#"]))
772 {
773 $fields[$k] = $documentProfile::prepareFieldsData($document["#"][$mess["SALE_EXPORT_CONTRAGENTS"]][0]["#"][$mess["SALE_EXPORT_CONTRAGENT"]][0]["#"]);
774 }
775
776 break;
777 }
778 }
779 return $fields;
780 }
781
786 static protected function getFieldsInfo()
787 {
788 throw new Main\ArgumentException('The method is not implemented.');
789 }
790
791 public function openNodeDirectory($level, $name)
792 {
793 $name = static::getLangByCodeField($name);
794 return str_repeat("\t", $level)."<".$name.">\n";
795 }
796
797 public function closeNodeDirectory($level, $name)
798 {
799 $name = static::getLangByCodeField($name);
800 return str_repeat("\t", $level)."</".$name.">\n";
801 }
802
803 protected function formatXMLNode($level, $name, $value, $parameters=array())
804 {
805 $params = '';
806 if(count($parameters)>0)
807 {
808 foreach ($parameters as $code=>$v)
809 $params .= ' '.static::getLangByCodeField($code).'="'.$v.'" ';
810 }
811
812 $name = static::getLangByCodeField($name);
813 return str_repeat("\t", $level)."<".$name.$params.">".\CDataXML::xmlspecialchars($value)."</".$name.">\n";
814 }
815
820 public function output($level=0)
821 {
822 $fields = $this->getFieldValues();
823 return $this->outputXml($fields, $level);
824 }
825
830 protected function outputXml(array $fields, $level=0)
831 {
832 $xml = '';
833 foreach ($fields as $name=>$value)
834 {
835 if(is_array($value))
836 {
837 switch ($name)
838 {
839 case 'REK_VALUES':
840 $xml .= $this->outputXmlRekValue($level, $name, $value);
841 break;
842 case 'ITEMS':
843 $xml .= $this->outputXmlItems($level, $name, $value);
844 break;
845 case 'AGENT':
846 $profile = new ProfileDocument();
847 $profile->setFields($value);
848 $xml .= $this->openNodeDirectory($level, 'AGENTS');
849 $xml .= $this->openNodeDirectory($level+1, $profile->getNameNodeDocument());
850 $xml .= $profile->output($level+1);
851 $xml .= $this->closeNodeDirectory($level+1, $profile->getNameNodeDocument());
852 $xml .= $this->closeNodeDirectory($level, 'AGENTS');
853 break;
854 case 'STORIES':
855 $xml .= $this->outputXmlStories($level, $name, $value);
856 break;
857 case 'TAXES':
858 $xml .= $this->outputXmlTaxes($level, $name, $value);
859 break;
860 case 'DISCOUNTS':
861 $xml .= $this->outputXmlDiscounts($level, $name, $value);
862 break;
863 }
864 }
865 else
866 $xml .= $this->formatXMLNode($level, $name, $value);
867
868 }
869 return $xml;
870 }
871
876 public static function getLangByCodeField($code)
877 {
878 $message = static::getMessageExport();
879
880 if(isset($message['CC_BSC1_'.$code]))
881 {
882 return $message['CC_BSC1_'.$code];
883 }
884 elseif(isset($message['SALE_EXPORT_'.$code]))
885 {
886 return $message['SALE_EXPORT_'.$code];
887 }
888 else
889 {
890 return $code;
891 }
892 }
893
894 protected function outputXmlRekValue($level, $name, $value)
895 {
896 $result ='';
897 $result .= $this->openNodeDirectory($level+0, $name);
898 foreach ($value as $list)
899 {
900 $result .= $this->openNodeDirectory($level+1, 'REK_VALUE');
901 foreach ($list as $k=>$v)
902 $result .= $this->formatXMLNode($level+2, $k, $v);
903 $result .= $this->closeNodeDirectory($level+1, 'REK_VALUE');
904 }
905 $result .= $this->closeNodeDirectory($level+0, $name);
906 return $result;
907 }
908
909 protected function outputXmlUnits($level, $name, $list)
910 {
911 $result = '';
912 $result .= $this->openNodeDirectory($level+0, $name);
913 foreach ($list as $k=>$v)
914 $result .= $this->formatXMLNode($level+1, $k, $v);
915 $result .= $this->closeNodeDirectory($level+0, $name);
916
917 return $result;
918 }
919
920 protected function outputXmlBaseUnit($level, $name, $value)
921 {
922 return $this->formatXMLNode($level+0, $name, '', array(
923 "CODE"=>$value,
924 "FULL_NAME_UNIT"=>static::getLangByCodeField("SHTUKA"),
925 "INTERNATIONAL_ABR"=>static::getLangByCodeField("RCE")
926 ));
927 }
928
929 protected function outputXmlItems($level, $name, $items)
930 {
931 $result = '';
932 $result .= $this->openNodeDirectory($level+0, $name);
933
934 foreach ($items as $item)
935 {
936 $result .= $this->openNodeDirectory($level+1, 'ITEM');
937
938 foreach ($item as $code=>$value)
939 {
940 if(is_array($value))
941 {
942 switch ($code)
943 {
944 case 'REK_VALUES':
945 $result .= $this->outputXmlRekValue($level+2, $code, $value);
946 break;
947 case 'ITEM_UNIT':
948 $result .= $this->outputXmlUnits($level+2, $code, $value);
949 break;
950 case 'DISCOUNTS':
951 $result .= $this->outputXmlDiscounts($level+2, $code, $value);
952 break;
953 case 'TAX_RATES':
954 $result .= $this->outputXmlTaxRates($level+2, $code, array($value));
955 break;
956 case 'TAXES':
957 $result .= $this->outputXmlTaxes($level+2, $code, array($value));
958 break;
959 }
960 }
961 elseif ($code == 'BASE_UNIT')
962 $result .= $this->outputXmlBaseUnit($level+2, $code, $value);
963 else
964 $result .= $this->formatXMLNode($level+2, $code, $value);
965 }
966
967 $result .= $this->closeNodeDirectory($level+1, 'ITEM');
968 }
969 $result .= $this->closeNodeDirectory($level+0, $name);
970 return $result;
971 }
972
973 protected function outputXmlAddress($level, $addresses)
974 {
975 $result = '';
976 foreach ($addresses as $code=>$address)
977 {
978 if(is_array($address))
979 {
980 foreach ($address as $values)
981 {
982 $result .= $this->openNodeDirectory($level+0, $code);
983 foreach ($values as $k=>$v)
984 $result .= $this->formatXMLNode($level+1, $k, $v);
985 $result .= $this->closeNodeDirectory($level+0, $code);
986 }
987 }
988 else
989 $result .= $this->formatXMLNode($level+0, $code, $address);
990 }
991 return $result;
992 }
993
994 protected function outputXmlStories($level, $name, $stories)
995 {
996 $result ='';
997 $result .= $this->openNodeDirectory($level+0, $name);
998
999 foreach ($stories as $store)
1000 {
1001 $result .= $this->openNodeDirectory($level+1, 'STORY');
1002 foreach ($store as $code=>$value)
1003 {
1004 if(is_array($value))
1005 {
1006 switch ($code)
1007 {
1008 case 'ADDRESS':
1009 case 'CONTACTS':
1010 $result .= $this->openNodeDirectory($level+2, $code);
1011 $result .= $this->outputXmlAddress($level+3, $value);
1012 $result .= $this->closeNodeDirectory($level+2, $code);
1013 break;
1014 }
1015 }
1016 else
1017 $result .= $this->formatXMLNode($level+2, $code, $value);
1018 }
1019 $result .= $this->closeNodeDirectory($level+1, 'STORY');
1020 }
1021 $result .= $this->closeNodeDirectory($level+0, $name);
1022
1023 return $result;
1024 }
1025
1026 protected function outputXmlTaxRates($level, $name, $taxes)
1027 {
1028 $result ='';
1029 $result .= $this->openNodeDirectory($level+0, $name);
1030
1031 foreach ($taxes as $tax)
1032 {
1033 $result .= $this->openNodeDirectory($level+1, 'RATE');
1034
1035 foreach ($tax as $k=>$v)
1036 $result .= $this->formatXMLNode($level+2, $k, $v);
1037
1038 $result .= $this->closeNodeDirectory($level+1, 'RATE');
1039 }
1040 $result .= $this->closeNodeDirectory($level+0, $name);
1041 return $result;
1042 }
1043
1044 protected function outputXmlTaxes($level, $name, $taxes)
1045 {
1046 $result ='';
1047 $result .= $this->openNodeDirectory($level+0, $name);
1048
1049 foreach ($taxes as $tax)
1050 {
1051 $result .= $this->openNodeDirectory($level+1, 'TAX');
1052
1053 foreach ($tax as $k=>$v)
1054 $result .= $this->formatXMLNode($level+2, $k, $v);
1055
1056 $result .= $this->closeNodeDirectory($level+1, 'TAX');
1057 }
1058 $result .= $this->closeNodeDirectory($level+0, $name);
1059 return $result;
1060 }
1061
1062 protected function outputXmlDiscounts($level, $name, $discounts)
1063 {
1064 $result ='';
1065 $result .= $this->openNodeDirectory($level+0, $name);
1066 $result .= $this->openNodeDirectory($level+1, 'DISCOUNT');
1067
1068 foreach ($discounts as $k=>$v)
1069 $result .= $this->formatXMLNode($level+2, $k, $v);
1070
1071 $result .= $this->closeNodeDirectory($level+1, 'DISCOUNT');
1072 $result .= $this->closeNodeDirectory($level+0, $name);
1073 return $result;
1074 }
1075
1076 public function getNameNodeDocument()
1077 {
1078 return 'DOCUMENT';
1079 }
1080}
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224
static prepareFieldsData(array $document)
outputXmlStories($level, $name, $stories)
static resolveUnitParams($value, array $fieldsInfo)
static resolveRawDocumentTypeId(array $document)
outputXmlBaseUnit($level, $name, $value)
outputXmlRekValue($level, $name, $value)
static resolveMarkingGroupParams($value, array $fieldsInfo)
outputXmlDiscounts($level, $name, $discounts)
static resolveCashBoxCheksParams(array $value, array $fieldsInfo)
static resolveItemsParams(array $document, array $fieldsInfo)
formatXMLNode($level, $name, $value, $parameters=array())
static resolveItemsArrayParams($value, $fieldName, array $fieldsInfo, array $document)
static resolveDiscountsParams(array $value, array $fieldsInfo)
static resolveTaxParams(array $value, array $fieldsInfo)
static internalizeFields(&$value, $fieldInfo=null)
static resolveMarkingParams(array $value, array $fieldsInfo)
static resolveTraitsParams(array $value, array $fieldsInfo)
static roundPrecision($value)