Skip to content

Commit

Permalink
Fix form warning messages in shipment creation form
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Apr 4, 2022
1 parent ddc4194 commit 9928898
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 41 deletions.
18 changes: 10 additions & 8 deletions client/src/i18n/en/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@
},
"PENDING_ACTIONS" : "Pending Actions",
"MESSAGES" : {
"INFO_NO_EXIT_TYPE" : "No exit type specified. Please select an exit type from the panels above to continue.",
"INFO_NEEDS_LOTS" : "Exit type set has been set. Please click \"Add\" to add rows to the grid.",
"WARN_PAST_DATE" : "You have chosen a date in the past. Only the lots available on the chosen date will be visible as well as the quantity on this date.",
"WARN_NOT_CONSUMABLE_INVOICE" : "The invoice does not have any consumable items in it. No lots have been automatically filled.",
"WARN_INSUFFICIENT_QUANTITY" : "There is not enough stock of {{hrText}} to fulfill the requisition. The requisition will be partially filled.",
"WARN_OUT_OF_STOCK_QUANTITY" : "There is no stock of {{hrText}} to fill the requisition. These item(s) have been skipped.",
"ERR_NO_DESTINATION" : "No destination is defined for this exit type. Please choose a destination to go with the exit type.",
"ERR_LOT_ERRORS" : "There are errors in the lots grid to be addressed.",
"ERR_NO_BARCODE_MATCH_IN_DEPOT" : "There is no lot matching that barcode in stock in the depot.",
"ERR_NO_DESTINATION" : "No destination is defined for this exit type. Please choose a destination to go with the exit type.",
"INFO_EXIT_TYPE_SET_NEEDS_LOTS" : "Exit type set has been set. Please click \"Add\" to add rows to the grid.",
"INFO_NEEDS_LOTS" : "Please click \"Add\" to add rows to the grid.",
"INFO_NO_EXIT_TYPE" : "No exit type specified. Please select an exit type from the panels above to continue.",
"SUCCESS_ALL_VALID" : "Looks good for submission!",
"SUCCESS_FILLED_N_ITEMS" : "Automatically selected {{count}} items from stock to fulfill requisition. Please check the lot numbers to ensure they are correct as you distribute the items.",
"SUCCESS_ALL_VALID" : "Looks good for submission!"
"WARN_INSUFFICIENT_QUANTITY" : "There is not enough stock of {{hrText}} to fulfill the requisition. The requisition will be partially filled.",
"WARN_MAIN_FORM_ERRORS" : "Please enter required fields in main form!",
"WARN_NOT_CONSUMABLE_INVOICE" : "The invoice does not have any consumable items in it. No lots have been automatically filled.",
"WARN_OUT_OF_STOCK_QUANTITY" : "There is no stock of {{hrText}} to fill the requisition. These item(s) have been skipped.",
"WARN_PAST_DATE" : "You have chosen a date in the past. Only the lots available on the chosen date will be visible as well as the quantity on this date."
},
"DEPOT_DISTRIBUTION" : "Depot Distribution",
"DIRECTION": " Movement direction",
Expand Down
17 changes: 9 additions & 8 deletions client/src/i18n/fr/stock.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,18 @@
},
"PENDING_ACTIONS" : "Actions en attente",
"MESSAGES" : {
"INFO_NO_EXIT_TYPE" : "Aucun type de sortie spécifié. Veuillez sélectionner un type de sortie dans les panneaux ci-dessus pour continuer.",
"INFO_NEEDS_LOTS" : "Le type de sortie défini a été défini. Veuillez cliquer sur \"Ajouter\" pour ajouter des lignes à la grille.",
"WARN_PAST_DATE" : "Vous avez choisi une date dans le passé. Seuls les lots disponibles à la date choisie seront visibles ainsi que la quantité à cette date.",
"WARN_NOT_CONSUMABLE_INVOICE" : "La facture ne contient aucun article consommable. Aucun lot n'a été pourvu automatiquement.",
"WARN_INSUFFICIENT_QUANTITY" : "Il n'y a pas assez de stock de {{hrText}} pour répondre à la demande. La réquisition sera partiellement remplie.",
"WARN_OUT_OF_STOCK_QUANTITY" : "Il n'y a pas de stock de {{hrText}} pour remplir la demande. Ces éléments ont été ignorés. ",
"ERR_NO_DESTINATION" : "Aucune destination n'est définie pour ce type de sortie. Veuillez choisir une destination pour aller avec le type de sortie.",
"ERR_LOT_ERRORS" : "Il y a des erreurs dans la grille des lots à corriger.",
"ERR_NO_BARCODE_MATCH_IN_DEPOT" : "Il n'y a pas de lot correspondant à ce code-barres en stock dans le dépôt.",
"ERR_NO_DESTINATION" : "Aucune destination n'est définie pour ce type de sortie. Veuillez choisir une destination pour aller avec le type de sortie.",
"INFO_EXIT_TYPE_SET_NEEDS_LOTS" : "Le type de sortie défini a été défini. Veuillez cliquer sur \"Ajouter\" pour ajouter des lignes à la grille.",
"INFO_NO_EXIT_TYPE" : "Aucun type de sortie spécifié. Veuillez sélectionner un type de sortie dans les panneaux ci-dessus pour continuer.",
"SUCCESS_ALL_VALID" : "Ça a l'air bon pour la soumission !",
"SUCCESS_FILLED_N_ITEMS" : "Sélection automatique de {{count}} articles du stock pour répondre à la demande. Veuillez vérifier les numéros de lot pour vous assurer qu'ils sont corrects lorsque vous distribuez les articles.",
"SUCCESS_ALL_VALID" : "Ça a l'air bon pour la soumission !"
"WARN_INSUFFICIENT_QUANTITY" : "Il n'y a pas assez de stock de {{hrText}} pour répondre à la demande. La réquisition sera partiellement remplie.",
"WARN_MAIN_FORM_ERRORS" : "Veuillez saisir les éléments requis dans le formulaire principal !",
"WARN_NOT_CONSUMABLE_INVOICE" : "La facture ne contient aucun article consommable. Aucun lot n'a été pourvu automatiquement.",
"WARN_OUT_OF_STOCK_QUANTITY" : "Il n'y a pas de stock de {{hrText}} pour remplir la demande. Ces éléments ont été ignorés. ",
"WARN_PAST_DATE" : "Vous avez choisi une date dans le passé. Seuls les lots disponibles à la date choisie seront visibles ainsi que la quantité à cette date."
},
"DEPOT_DISTRIBUTION" : "Distribution au dépôt",
"DIRECTION": "Direction du movement",
Expand Down
7 changes: 4 additions & 3 deletions client/src/modules/shipment/create-shipment.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ol class="headercrumb">
<li class="static" translate>SHIPMENT.SHIPMENTS</li>
<li><a ui-sref="shipments" translate>SHIPMENT.SHIPMENT_REGISTRY</a></li>
<li class="title">
<li class="title">
<span translate>SHIPMENT.NEW_SHIPMENT </span>&nbsp;
<span ng-if="CreateShipCtrl.depot.uuid" class="label label-primary">{{ CreateShipCtrl.depot.text }}</span>
</li>
Expand All @@ -28,7 +28,7 @@
<div class="container-fluid">

<form name="ShipmentForm" bh-submit="CreateShipCtrl.submit(ShipmentForm)" novalidate>

<!-- date and note -->
<div class="row">
<div class="col-md-4">
Expand All @@ -54,7 +54,8 @@
label="SHIPMENT.ANTICIPATED_DELIVERY_DATE"
date-value="CreateShipCtrl.shipment.anticipated_delivery_date"
allow-future-date="true"
on-change="CreateShipCtrl.setDate(date)">
on-change="CreateShipCtrl.setDate(date)"
required="true">
</bh-date-editor>

<div ng-if="CreateShipCtrl.dateMessageWarning" class="form-group">
Expand Down
40 changes: 27 additions & 13 deletions client/src/modules/shipment/create-shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function CreateShipmentController(

vm.stockForm = new StockForm('ShipmentForm');
vm.stockForm.setAllowExpired(false);
vm.stockForm.setExitTypePredefined(true);

const gridFooterTemplate = `
<div style="margin-left: 10px;">
Expand Down Expand Up @@ -127,37 +128,37 @@ function CreateShipmentController(
}, 0);
};

vm.validate = () => {
vm.stockForm.validate();
vm.validateItems = () => {
vm.stockForm.validate(true);
vm.messages = vm.stockForm.messages();
};

vm.configureItem = function configureItem(row, lot) {
vm.stockForm.configureItem(row, lot);
vm.validate();
vm.validateItems();
};

vm.addItems = function addItems(numItems) {
vm.stockForm.addItems(numItems);
vm.validate();
vm.validateItems();
};

vm.removeItem = function removeItem(uuid) {
vm.stockForm.removeItem(uuid);
vm.validate();
vm.validateItems();
};

vm.setDate = function setDate(date) {
vm.shipment.anticipated_delivery_date = date;
vm.stockForm.setDate(date);
vm.validate();
vm.validateItems();
};

vm.setLotFromDropdown = function setLotFromDropdown(row, lot) {
vm.stockForm._pool.use(lot.lot_uuid);
row.configure(lot);
vm.stockForm.updateLotListings(row.inventory_uuid);
vm.validate();
vm.validateItems();
};

vm.getLotByBarcode = function getLotByBarcode() {
Expand Down Expand Up @@ -192,7 +193,7 @@ function CreateShipmentController(
vm.stockForm.setLossDistribution();

// run validation
vm.validate();
vm.validateItems();

// refresh quantity available
return refreshQuantityAvailable(vm.depot);
Expand Down Expand Up @@ -225,7 +226,7 @@ function CreateShipmentController(
vm.hasError = false;

vm.stockForm.setup();
vm.validate();
vm.validateItems();

// load the shipment for update
loadShipment();
Expand All @@ -244,7 +245,7 @@ function CreateShipmentController(
}
});

vm.validate();
vm.validateItems();

return Shipment.read(null, { depot_uuid : depot.uuid, dateTo, skipTags : true });
})
Expand All @@ -268,11 +269,24 @@ function CreateShipmentController(
}

function submit(form) {
if (form.$invalid) { return null; }

const isValidForSubmission = vm.stockForm.validate();
if (form.$invalid) {
vm.validateItems();

// Prepend general form needs fixing message
const formMsg = {
type : 'warn',
text : 'STOCK.MESSAGES.WARN_MAIN_FORM_ERRORS',
keys : {},
};
vm.messages.unshift(formMsg);
Notify.danger(formMsg.text, 5000);
return null;
}

const isValidForSubmission = vm.stockForm.validate(true);

// check if the form is valid
// check if the lots in the form are valid
if (isValidForSubmission === false) {

let firstElement = true;
Expand Down
28 changes: 21 additions & 7 deletions client/src/modules/stock/StockExitForm.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ function StockExitFormService(
const today = new Date();
const $date = $filter('date');

const INFO_NO_EXIT_TYPE = 'STOCK.MESSAGES.INFO_NO_EXIT_TYPE';
const ERR_LOT_ERRORS = 'STOCK.MESSAGES.ERR_LOT_ERRORS';
const ERR_NO_BARCODE_MATCH_IN_DEPOT = 'STOCK.MESSAGES.ERR_NO_BARCODE_MATCH_IN_DEPOT';
const ERR_NO_DESTINATION = 'STOCK.MESSAGES.ERR_NO_DESTINATION';
const INFO_EXIT_TYPE_SET_NEEDS_LOTS = 'STOCK.MESSAGES.INFO_EXIT_TYPE_SET_NEEDS_LOTS';
const INFO_NEEDS_LOTS = 'STOCK.MESSAGES.INFO_NEEDS_LOTS';
const INFO_NO_EXIT_TYPE = 'STOCK.MESSAGES.INFO_NO_EXIT_TYPE';
const SUCCESS_FILLED_N_ITEMS = 'STOCK.MESSAGES.SUCCESS_FILLED_N_ITEMS';
const WARN_PAST_DATE = 'STOCK.MESSAGES.WARN_PAST_DATE';
const WARN_NOT_CONSUMABLE_INVOICE = 'STOCK.MESSAGES.WARN_NOT_CONSUMABLE_INVOICE';
const WARN_INSUFFICIENT_QUANTITY = 'STOCK.MESSAGES.WARN_INSUFFICIENT_QUANTITY';
const WARN_NOT_CONSUMABLE_INVOICE = 'STOCK.MESSAGES.WARN_NOT_CONSUMABLE_INVOICE';
const WARN_OUT_OF_STOCK_QUANTITY = 'STOCK.MESSAGES.WARN_OUT_OF_STOCK_QUANTITY';
const ERR_NO_DESTINATION = 'STOCK.MESSAGES.ERR_NO_DESTINATION';
const ERR_NO_BARCODE_MATCH_IN_DEPOT = 'STOCK.MESSAGES.ERR_NO_BARCODE_MATCH_IN_DEPOT';
const ERR_LOT_ERRORS = 'STOCK.MESSAGES.ERR_LOT_ERRORS';
const WARN_PAST_DATE = 'STOCK.MESSAGES.WARN_PAST_DATE';

/**
* @constructor
Expand All @@ -49,6 +50,7 @@ function StockExitFormService(
this.details = { is_exit : 1 };
this.store = new Store({ identifier : 'uuid', data : [] });
this.allowExpired = true;
this.exitTypePredefined = false;

// this variable is private and will contain the stock for the current depot.
this._pool = new Pool('lot_uuid', []);
Expand All @@ -67,6 +69,14 @@ function StockExitFormService(
this.allowExpired = flag;
};

/**
* Set flag that the exit type is predefined
* @param {boolean} flag
*/
StockExitForm.prototype.setExitTypePredefined = function setExitTypePredefined(flag) {
this.exitTypePredefined = flag;
};

StockExitForm.prototype._toggleInfoMessage = function _toggleInfoMessage(
shouldShowMsg, msgType, msgText, msgKeys = {},
) {
Expand Down Expand Up @@ -747,7 +757,11 @@ function StockExitFormService(
&& !hasDestinationError
&& this.store.data.length === 0;

this._toggleInfoMessage(showNeedsLotsInfoMessage, 'info', INFO_NEEDS_LOTS, this.details);
if (this.exitTypePredefined) {
this._toggleInfoMessage(showNeedsLotsInfoMessage, 'info', INFO_NEEDS_LOTS, this.details);
} else {
this._toggleInfoMessage(showNeedsLotsInfoMessage, 'info', INFO_EXIT_TYPE_SET_NEEDS_LOTS, this.details);
}

// remove the barcode error next validation
this._toggleInfoMessage(false, 'error', ERR_NO_BARCODE_MATCH_IN_DEPOT);
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/templates/bhInputText.tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="form-group"
input-text>

<label class="control-label" ng-class="{ 'col-md-3' : $ctrl.leftLabel}" translate> {{$ctrl.label}}</label>
<label class="control-label" ng-class="{ 'col-md-3' : $ctrl.leftLabel}" translate> {{$ctrl.label}}</label>

<i
ng-if="$ctrl.description"
Expand All @@ -26,7 +26,7 @@
autocomplete="{{$ctrl.autocomplete}}"
ng-change="$ctrl.valueChange()"
input-text-field
class='form-control'
class="form-control"
ng-required="$ctrl.required"/>

<div class="help-block"
Expand Down

0 comments on commit 9928898

Please sign in to comment.