Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#VP-2481 add shipment item select #157

Merged
merged 6 commits into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -150,6 +150,12 @@ public override OrderOperation ToModel(OrderOperation operation)
return property;
}).ToArray();

//Link shipment item with order lineItem
foreach (var shipmentItem in order.Shipments.SelectMany(x => x.Items))
{
shipmentItem.LineItem = order.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItemId);
}

base.ToModel(order);

Sum = order.Total;
Expand Down
13 changes: 8 additions & 5 deletions src/VirtoCommerce.OrdersModule.Data/Model/ShipmentItemEntity.cs
Expand Up @@ -47,6 +47,13 @@ public virtual ShipmentItem ToModel(ShipmentItem shipmentItem)
shipmentItem.BarCode = BarCode;
shipmentItem.Quantity = Quantity;

shipmentItem.LineItemId = LineItemId;

if (ModelLineItem != null)
{
shipmentItem.LineItem = ModelLineItem;
}

return shipmentItem;
}

Expand All @@ -69,11 +76,7 @@ public virtual ShipmentItemEntity FromModel(ShipmentItem shipmentItem, PrimaryKe
if (shipmentItem.LineItem != null)
{
LineItemId = shipmentItem.LineItem.Id;
//Store ModelLineItem for future linking with the order line item only for new objects otherwise we will get error when saving
if (shipmentItem.LineItem.IsTransient())
{
ModelLineItem = shipmentItem.LineItem;
}
ModelLineItem = shipmentItem.LineItem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you test these scenarios to be confident that you don't introduce regress bugs?

  • save new order with the new shipment with items
  • update exists order shipment with new shipment items
  • update exists order with the new shipment with items

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it.

Copy link
Contributor Author

@kostyrin kostyrin Jun 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, there is no scenario - save new order with the new shipment with items.
How to do it? Without exists LineItemId?
there are no links with Order.LineItemId.
Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot insert the value NULL into column 'LineItemId', table 'VirtoCommerce3.dbo.OrderShipmentItem'; column does not allow nulls. INSERT fails.

@akak1977 saving new shipment - fixed

}

return this;
Expand Down
@@ -0,0 +1,66 @@
angular.module('virtoCommerce.orderModule')
.controller('virtoCommerce.orderModule.orderItemSelectController', ['$scope', 'platformWebApp.bladeUtils',
function ($scope, bladeUtils) {
var blade = $scope.blade;
var bladeNavigationService = bladeUtils.bladeNavigationService;

if (!blade.title) {
blade.title = "Select Order items...";
}

$scope.options = angular.extend({
showCheckingMultiple: true,
allowCheckingItem: true,
selectedItemIds: [],
gridColumns: []
}, blade.options);

blade.refresh = function () {
$scope.items = angular.copy(blade.orderItems);
_.each($scope.items, function (item) {
item.quantityOnShipment = item.quantity;
});

if ($scope.options.onItemsLoaded) {
$scope.options.onItemsLoaded($scope.items);
}

blade.isLoading = false;
};

blade.toolbarCommands = [
{
name: "orders.commands.add-item", icon: 'fa fa-plus',
executeMethod: function (blade) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR "blade" hides or potentially hides a variable declared in an outer scope at line 4. rule

var selectedItems = _.map(_.where($scope.items, {selected: true}), function(item) {
return { lineItemId: item.id, lineItem: item, quantity: item.quantityOnShipment };
});
_.each(selectedItems, function (item) {
blade.currentEntity.items.push(item);
yecli marked this conversation as resolved.
Show resolved Hide resolved
});

bladeNavigationService.closeBlade(blade);
},
canExecuteMethod: function () {
return _.any($scope.items, function (x) { return x.selected; });
},
permission: blade.updatePermission
},
{
name: "platform.commands.remove", icon: 'fa fa-trash-o',
executeMethod: function () {
var lineItems = blade.currentEntity.items;
blade.currentEntity.items = _.difference(lineItems, _.filter(lineItems, function (x) { return x.selected }));
blade.recalculateFn();
$scope.pageSettings.totalItems = blade.currentEntity.items.length;
},
canExecuteMethod: function () {
return _.any(blade.currentEntity.items, function (x) { return x.selected; });
},
permission: blade.updatePermission
}
];

blade.refresh();

}]);
@@ -0,0 +1,55 @@
<div class="blade-content __xlarge-wide">
<div class="blade-inner">
<div class="inner-block">
<form name="orderForm" novalidate></form>
<div class="table-wrapper">
<table class="table">
<thead>
<tr>
<th class="table-col __product-control">
<label class="form-control __checkbox">
<input type="checkbox" ng-model="blade.selectedAll" ng-change="checkAll(blade.selectedAll)" />
<span class="check"></span>
</label>
</th>
<th class="table-col __proudct-img"></th>
<th class="table-col">{{ 'orders.blades.customerOrder-items.labels.item' | translate }}</th>
<th class="table-col">{{ 'orders.blades.customerOrder-items.labels.quantity' | translate }}</th>
<th class="table-col">{{ 'orders.blades.customerOrder-items.labels.available' | translate }}</th>
</tr>
</thead>
<tbody>
<tr class="table-item" ng-repeat="data in items" ng-class="{'__selected': $index === blade.selectedNodeId}" ng-click='blade.selectedNodeId = $index'>
<td class="table-col">
<label class="form-control __checkbox">
<input type="checkbox" ng-model="data.selected">
<span class="check"></span>
</label>
</td>
<td class="table-col">
<div class="product-img">
<div class="image" style="background-image: url({{data.imageUrl}})" ng-if="data.imageUrl" ng-click="openItemDetail(data)"></div>
<i class="table-ico fa fa-image" ng-if="!data.imageUrl" />
</div>
</td>
<td class="table-col">
<span ng-class="{'error': data.avail <= 0}">{{data.name}}</span>
</td>
<td class="table-col">
<div class="form-input __mini __inline">
<div class="form-input __mini __number">
<input smart-float num-type="integer" required ng-model="data.quantityOnShipment" ng-model-options="{ updateOn: 'blur' }" ng-change="blade.recalculateFn()" id="quantity{{$index}}" focus-on="quantity{{$index}}">
</div>
</div>
</td>
<td class="table-col">
<span ng-class="{'error': data.avail <= 0}">{{(data.quantity || 0) | number:0}}</span>
</td>

</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Expand Up @@ -6,8 +6,12 @@ angular.module('virtoCommerce.orderModule')

//pagination settings
$scope.pageSettings = {};
$scope.totals = {};
$scope.pageSettings.totalItems = blade.currentEntity.items.length;
$scope.totals = {};
if (blade.currentEntity.items) {
$scope.pageSettings.totalItems = blade.currentEntity.items.length;
} else {
blade.currentEntity.items = [];
}
$scope.pageSettings.currentPage = 1;
$scope.pageSettings.numPages = 5;
$scope.pageSettings.itemsPerPageCount = 4;
Expand All @@ -28,7 +32,7 @@ angular.module('virtoCommerce.orderModule')
openAddEntityWizard();
},
canExecuteMethod: function () {
return false;
return blade.currentEntity.operationType === 'Shipment';
},
permission: blade.updatePermission
},
Expand Down Expand Up @@ -61,5 +65,43 @@ angular.module('virtoCommerce.orderModule')
});
};

function openAddEntityWizard() {
var options = {
checkItemFn: function (listItem, isSelected) {
if (isSelected) {
if (_.all(selectedProducts, function (x) { return x.id != listItem.id; })) {
selectedProducts.push(listItem);
}
}
else {
selectedProducts = _.reject(selectedProducts, function (x) { return x.id == listItem.id; });
}
}
};
var newBlade = {
id: "OrderItemsSelect",
currentEntity: blade.currentEntity,
orderItems: blade.parentBlade.parentBlade.currentEntity.items,
title: "orders.blades.catalog-items-select.title",
controller: 'virtoCommerce.orderModule.orderItemSelectController',
template: 'Modules/$(VirtoCommerce.Orders)/Scripts/blades/customerOrder-items-select.tpl.html',
options: options,
breadcrumbs: [],
toolbarCommands: [
{
name: "orders.commands.add-selected", icon: 'fa fa-plus',
executeMethod: function (blade) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR "blade" hides or potentially hides a variable declared in an outer scope at line 3. rule

//addProductsToOrder(selectedProducts);
selectedProducts.length = 0;
bladeNavigationService.closeBlade(blade);
},
canExecuteMethod: function () {
return selectedProducts.length > 0;
}
}]
};
bladeNavigationService.showBlade(newBlade, $scope.blade);
}

blade.refresh();
}]);
Expand Up @@ -18,13 +18,13 @@
</label>
</th>
<th class="table-col __proudct-img">{{ 'orders.blades.shipment-items.labels.item' | translate }}</th>
<th class="table-col"></th>
<th class="table-col">{{ 'orders.blades.shipment-items.labels.quantity' | translate }}</th>
<th class="table-col">{{ 'orders.blades.shipment-items.labels.price' | translate }}</th>
<th class="table-col">{{ 'orders.blades.shipment-items.labels.total' | translate }}</th>
</tr>
</thead>
<tbody>
<tr class="table-item" ng-repeat-start="data in blade.currentEntity.items" ng-class="{'__selected': data.id === selectedNodeId}" context-menu data-target="col_menu_{{data.id}}" ng-click='selectItem(data)'>
<tr class="table-item" ng-repeat="data in blade.currentEntity.items" ng-class="{'__selected': data.id === selectedNodeId}" context-menu data-target="col_menu_{{data.id}}" ng-click='selectItem(data)'>
<td class="table-col">
<label class="form-control __checkbox">
<input type="checkbox" ng-model="data.selected">
Expand All @@ -36,42 +36,20 @@
<div class="image" style="background-image: url({{data.lineItem.imageUrl}})" ng-if="data.lineItem.imageUrl" ng-click="openItemDetail(data)"></div>
<i class="table-ico fa fa-image" ng-if="!data.lineItem.imageUrl" />
</div>
<ul role="menu" class="menu __context" id="col_menu_{{data.id}}">
<li class="menu-item" ng-click='edit(data)'>
<i class="menu-ico fa fa-edit"></i> {{'platform.commands.manage' | translate}}
</li>
<li class="menu-item" ng-click='delete()'>
<i class="menu-ico fa fa-trash-o"></i> {{'platform.commands.delete' | translate}}
</li>
</ul>

</td>
<td class="table-col">{{data.lineItem.name}}</td>
<td class="table-col">
<div class="__mini __number">
{{data.quantity | number:9}}
{{data.quantity | number:0}}
</div>
</td>
<td class="table-col">
<div class="form-input __mini">
{{data.lineItem.price | currency:data.lineItem.currency | showPrice:blade.isVisiblePrices}}
</div>
</td>
<td class="table-col __total">
<span>{{data._total | currency:data.lineItem.currency | showPrice:blade.isVisiblePrices}}</span>
</td>
</tr>
<tr ng-repeat-end class="table-item" ng-class="{'__selected': data.id === selectedNodeId}" context-menu data-target="col_menu_{{data.id}}" ng-click='selectItem(data)'>
<td class="table-head" colspan="9" ng-click="openItemDetail(data)">
{{data.lineItem.name}}
<ul role="menu" class="menu __context" id="col_menu_{{data.id}}">
<li class="menu-item" ng-click='edit(data)'>
<i class="menu-ico fa fa-edit"></i> {{'platform.commands.manage' | translate}}
</li>
<li class="menu-item" ng-click='delete()'>
<i class="menu-ico fa fa-trash-o"></i> {{'platform.commands.delete' | translate}}
</li>
</ul>
</td>
</tr>
</tr>
</tbody>
</table>
<ng-include src="'pagerTemplate.html'"></ng-include>
Expand Down