text: app.controller('purchaseOrderShow', ['$scope', '$http', '$rootScope', '$filter', '$compile', function($scope, $http, $rootScope, $filter, $compile) {
      $scope.title = 'Detail Order Pembelian';
      $scope.data = {}
      var path = window.location.pathname;
      id = path.replace(/.+\/(\d+)/, '$1');
  
  
      purchase_order_detail_datatable = $('#purchase_order_detail_datatable').DataTable({
         dom: 'rt',
          columns:[
            {
              data: null, 
              orderable : false,
              searchable : false,
              render : function(resp) {
                  var index = $scope.formData.detail.length - 1
                  return "<% formData.detail[" + index + "].item_name %>"
              }
            },
            {
              data: null, 
              orderable : false,
              searchable : false,
              className : 'text-right',  
              render : function(resp) {
                  var index = $scope.formData.detail.length - 1
                  return "<% formData.detail[" + index + "].qty | number %>"
              }
            },
            {
              data: null, 
              orderable : false,
              searchable : false,
              className : 'text-right',  
              render : function(resp) {
                  var index = $scope.formData.detail.length - 1
                  return "<% formData.detail[" + index + "].used_qty %>"
              }
            },
            {
              data: null, 
              orderable : false,
              searchable : false,
              className : 'text-right',  
              render : function(resp) {
                  var index = $scope.formData.detail.length - 1
                  return "<% formData.detail[" + index + "].purchase_price | number %>"
              }
            },
            {
              data: null, 
              orderable : false,
              searchable : false,
              className : 'text-right',  
              render : function(resp) {
                  var index = $scope.formData.detail.length - 1
                  return "<% formData.detail[" + index + "].discount %>%"
              }
            }
          ],
          createdRow: function(row, data, dataIndex) {
            $compile(angular.element(row).contents())($scope);
            $(row).find('input').focus()
          }
      });
  
  
    $scope.delete = function(id) {
      is_delete = confirm('Apakah anda yakin transaksi ini akan dihapus ?');
      if(is_delete)
          $http.delete(baseUrl + '/controller/pharmacy/purchase_order/' + id).then(function(data) {
              toastr.success("Data Berhasil dihapus")
              setTimeout(function() {
                  location.href = baseUrl + '/pharmacy/purchase_order'
              }, 800)
          }, function(error) {
            if (error.status==422) {
              var det="";
              angular.forEach(error.data.errors,function(val,i) {
                det+="- "+val+"<br>";
              });
              toastr.warning(det,error.data.message);
            } else {
              toastr.error(error.data.message,"Error Has Found !");
            }
          });
    }
  
  
      $scope.insertItem = function(data = {}) {
          $scope.formData.detail.push(data)
          purchase_order_detail_datatable.row.add({}).draw()
      }
  
    $scope.show = function() {
        $http.get(baseUrl + '/controller/pharmacy/purchase_order/' + id).then(function(data) {
            $scope.formData = data.data
            var detail = data.data.detail
            var unit
            $scope.receipt_url = baseUrl + '/pharmacy/receipt/purchase_order/' + id + '/create'
            for(x in detail) {
                unit = detail[x]
                detail[x].item_name = unit.item.name
                $scope.insertItem(unit)
                $scope.checkStock(x, unit.item_id)
            }
  
  
      }, function(error) {
        $rootScope.disBtn=false;
        if (error.status==422) {
          var det="";
          angular.forEach(error.data.errors,function(val,i) {
            det+="- "+val+"<br>";
          });
          toastr.warning(det,error.data.message);
        } else {
          $scope.show()
          toastr.error(error.data.message,"Error Has Found !");
        }
      });
    }
  
    $scope.show()
  
  
      $scope.checkStock = function(index, item_id) {
        var param = {
            'item_id' : item_id,
            date_start : $scope.formData.date_start,
            date_end : $scope.formData.date_end
          }
  
        $http.get(baseUrl + '/controller/pharmacy/stock_transaction/check?' + $.param(param)).then(function(data) {
              $('#itemModal').modal('hide')
              $rootScope.disBtn=false;
              $scope.formData.detail[index].used_qty = data.data.qty
        }, function(error) {
              $rootScope.disBtn=false;
              if (error.status==422) {
                var det="";
                angular.forEach(error.data.errors,function(val,i) {
                  det+="- "+val+"<br>";
                });
                toastr.warning(det,error.data.message);
              } else {
                toastr.error(error.data.message,"Error Has Found !");
              }
        });
      }
  
  }]);