Advertisement
Guest User

Untitled

a guest
Feb 9th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 8.24 KB | None | 0 0
  1. import QtQuick 2.5
  2. import ui_components 1.0
  3. import core_components 1.0
  4. import QtQuick.Layouts 1.1
  5. import QtQuick.Controls 2.0
  6.  
  7. import QtQuick.Controls 1.4
  8. NNUIPage {
  9.     statusBarTitle: "Отчёт"
  10.  
  11.     property bool loading: false
  12.     property var inventarizationData:({inventory_result: {
  13.                                               wh_excess:[],
  14.                                               match: [],
  15.                                               site_excess: []
  16.                                           }})
  17.     property var scannedCodes:  session.stateMachine.context.scannedInventarizationCodes
  18.  
  19.     property var reportChapterOrder: ['wh_excess', 'match', 'site_excess']
  20.  
  21.     property var reportTypesInfo: ({
  22.                                        wh_excess: {
  23.                                            not_found_text: "Не найдено",
  24.                                            display_name: 'Есть на складе, но нет в системе',
  25.                                            color: "#173da6",
  26.                                        },
  27.                                        match: {
  28.                                            not_found_text: "Не найдены",
  29.                                            display_name: 'Успешно сопоставленные пачки',
  30.                                            color: "#18a556",
  31.                                        },
  32.                                        site_excess:{
  33.                                            not_found_text: "Не обнаружены",
  34.                                            display_name: 'Нет на складе, но есть в системе',
  35.                                            color: "#f06730",
  36.                                        },
  37.                                    })
  38.  
  39.     function chapterByName(name) {
  40.         return chaptersRepeater.itemAt(reportChapterOrder.indexOf(name));
  41.     }
  42.  
  43.     function getVolume(batchData) {
  44.         return batchData.batch_length
  45.                 *batchData.batch_width
  46.                 *batchData.batch_thickness
  47.                 *batchData.batch_quantity/1000000000.0;
  48.     }
  49.  
  50.     RowLayout {
  51.         anchors.fill: parent
  52.         Repeater {
  53.             id: chaptersRepeater
  54.             model: reportChapterOrder
  55.             ColumnLayout {
  56.                 Layout.fillHeight: true
  57.  
  58.                 property var chapterName: modelData
  59.                 property var chapterData: reportTypesInfo[chapterName]
  60.                 property double volume: 0.0
  61.                 property var batchModel: ListModel{
  62.                     onCountChanged: {
  63.                         var v = 0.0
  64.                         for(var i = 0; i < count; i ++) {
  65.                             if(get(i).batch_not_found !== true)
  66.                                 v += getVolume(get(i));
  67.                         }
  68.                         volume = v;
  69.                     }
  70.                 }
  71.  
  72.                 function fillFromData(inputData) {
  73.                     asyncFiller.sendMessage({model: batchModel, sourceData: inputData[chapterName]});
  74.                 }
  75.  
  76.                 WorkerScript { id: asyncFiller; source: "model_filler.js" }
  77.  
  78.                 NNText {
  79.                     anchors.horizontalCenter: parent.horizontalCenter
  80.                     text: chapterData.display_name
  81.                     font.pixelSize: 22
  82.                     height: 50
  83.                     verticalAlignment: Text.AlignBottom
  84.                     opacity: batchModel.count > 0 ? 1.0: 0.0
  85.                 }
  86.                 NNText {
  87.                     text: chapterData.not_found_text
  88.                     anchors.horizontalCenter: parent.horizontalCenter
  89.                     font.pixelSize: 19
  90.                     visible: batchModel.count == 0 && !loading
  91.                     color: "#f94b2a"
  92.                 }
  93.                 NNText {
  94.                     id: textSummaryWHExcess
  95.                     anchors.horizontalCenter: parent.horizontalCenter
  96.                     font.pixelSize: 19
  97.                     visible: batchModel.count > 0
  98.                     color: "#e1feaf"
  99.                     text: "%1 шт., %2 м³".arg(batchModel.count).arg(volume.toFixed(2))
  100.                 }
  101.                 BatchListView {
  102.  
  103.                     Layout.fillHeight: true
  104.                     anchors.horizontalCenter: parent.horizontalCenter
  105.                     model: batchModel
  106.                     delegate: BatchBlock{
  107.                         blColor: chapterData.color
  108.                         val2ui: val2uiTransform
  109.                     }
  110.                 }
  111.             }
  112.         }
  113.     }
  114.  
  115.     BusyIndicator {
  116.         id: busyIndicator
  117.         anchors.centerIn: parent
  118.         width: 100
  119.         height: 100
  120.         running: loading
  121.     }
  122.  
  123.  
  124.     onScannedCodesChanged: {
  125.         if(scannedCodes != undefined && scannedCodes.length>0) {
  126.             loading = true
  127.             rest.post('inventory',
  128.                       {export:scannedCodes},
  129.                       function(resp, code) {
  130.                           if(code != 200)
  131.                           {
  132.                               console.log("'inventory request failed'");
  133.                               loading = false;
  134.                               return;
  135.                           }
  136.                           var rcvCounter = 0;
  137.  
  138.                           function createHandler(batchIndex) {
  139.                               return function(d, code) {
  140.                                   var dt = getEmptyData();
  141.  
  142.                                   if(d.length === 0) {
  143.                                       dt.batch_not_found = true;
  144.                                       console.log("Could not find batch: ", code);
  145.                                   }
  146.                                   else {
  147.                                       d[0].not_found = false;
  148.                                       d[0].deleted = false;
  149.                                       fillBatchData(dt, d[0]);
  150.                                   }
  151.                                   dt['batch_time'] = dt.batch_timestamp.slice(0, -13);
  152.                                   chapterByName('wh_excess').batchModel.append(dt);
  153.  
  154.                                   rcvCounter ++;
  155.                                   if(rcvCounter == resp.inventory_result.wh_excess.length) {
  156.                                       loading = false;
  157.                                   }
  158.                               };
  159.                           }
  160.  
  161.                           if (resp.inventory_result.wh_excess.length > 0) {
  162.                               loading = true;
  163.                               for(var i = 0; i < resp.inventory_result.wh_excess.length; i ++) {
  164.                                   rest.get("plywood_batches?barcode_id="+resp.inventory_result.wh_excess[i].pack_id, createHandler(i), true);
  165.                               }
  166.                           } else {
  167.                               loading = false;
  168.                           }
  169.  
  170.                           chapterByName('match').fillFromData(resp.inventory_result);
  171.                           chapterByName('site_excess').fillFromData(resp.inventory_result);
  172.                       });
  173.         }
  174.     }
  175.  
  176.     onDisappeared: {
  177.         session.stateMachine.context.scannedInventarizationCodes = [];
  178.         session.stateMachine.contextChanged();
  179.         inventarizationData = {inventory_result: {
  180.                 wh_excess:[],
  181.                 match: [],
  182.                 site_excess: []
  183.             }};
  184.         chaptersRepeater.model = []
  185.         chaptersRepeater.model = reportChapterOrder
  186.     }
  187.  
  188.     function fillBatchData(bd, serverData) {
  189.         for(var p in serverData) {
  190.             bd['batch_' + p] = serverData[p]
  191.         }
  192.     }
  193.  
  194.     function getEmptyData() {
  195.         return   {
  196.             batch_pack_id: null,
  197.             batch_not_found: null,
  198.             batch_quantity: null,
  199.             batch_shipped: null,
  200.             batch_length: null,
  201.             batch_barcode_confirmed: null,
  202.             batch_width: null,
  203.             batch_deleted: null,
  204.             batch_thickness: null,
  205.             batch_sort_1: null,
  206.             batch_sort_2: null,
  207.             batch_comment: null,
  208.             batch_timestamp: null,
  209.         };
  210.     }
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement