This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Draft) New wrapVariable representation for conditional variab…
…les with whenTrue/whenFalse Signed-off-by: Jerome Simeon <[email protected]>
- Loading branch information
1 parent
352c0eb
commit 1ac046d
Showing
17 changed files
with
7,629 additions
and
7,405 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
examples/latedeliveryandpenaltyelse/data-noforcemajeure.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$class": "org.accordproject.latedeliveryandpenalty.TemplateModel", | ||
"forceMajeure": false, | ||
"penaltyDuration": { | ||
"$class": "org.accordproject.time.Duration", | ||
"amount": 2, | ||
"unit": "days" | ||
}, | ||
"penaltyPercentage": 10.5, | ||
"capPercentage": 55, | ||
"termination": { | ||
"$class": "org.accordproject.time.Duration", | ||
"amount": 15, | ||
"unit": "days" | ||
}, | ||
"fractionalPart": "days" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$class": "org.accordproject.latedeliveryandpenalty.TemplateModel", | ||
"forceMajeure": true, | ||
"penaltyDuration": { | ||
"$class": "org.accordproject.time.Duration", | ||
"amount": 2, | ||
"unit": "days" | ||
}, | ||
"penaltyPercentage": 10.5, | ||
"capPercentage": 55, | ||
"termination": { | ||
"$class": "org.accordproject.time.Duration", | ||
"amount": 15, | ||
"unit": "days" | ||
}, | ||
"fractionalPart": "days" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace org.accordproject.latedeliveryandpenalty | ||
|
||
import org.accordproject.cicero.runtime.* | ||
import org.accordproject.time.* | ||
|
||
// Declare a contract over a template model | ||
contract LateDeliveryAndPenalty over TemplateModel { | ||
// Clause checking for late delivery and calculating penalty | ||
clause latedeliveryandpenalty(request : LateDeliveryAndPenaltyRequest) : LateDeliveryAndPenaltyResponse { | ||
// Guard against calling late delivery clause too early | ||
let agreed = request.agreedDelivery; | ||
enforce isBefore(agreed,now()) else | ||
throw ErgoErrorResponse{ message: "Cannot exercise late delivery before delivery date" } | ||
; | ||
// Guard against force majeure | ||
enforce !contract.forceMajeure or !request.forceMajeure else | ||
return LateDeliveryAndPenaltyResponse{ | ||
penalty: 0.0, | ||
buyerMayTerminate: true | ||
} | ||
; | ||
|
||
// Calculate the time difference between current date and agreed upon date | ||
let diff = diffDurationAs(now(),agreed,~org.accordproject.time.TemporalUnit.days).amount; | ||
// Penalty formula | ||
let penalty = | ||
(integerToDouble(diff) / integerToDouble(contract.penaltyDuration.amount)) | ||
* contract.penaltyPercentage/100.0 * request.goodsValue; | ||
// Penalty may be capped | ||
let capped = min([penalty, contract.capPercentage * request.goodsValue / 100.0]); | ||
// Return the response with the penalty and termination determination | ||
return LateDeliveryAndPenaltyResponse{ | ||
penalty: capped, | ||
buyerMayTerminate: diff > contract.termination.amount | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace org.accordproject.latedeliveryandpenalty | ||
|
||
import org.accordproject.time.* | ||
|
||
/** | ||
* Defines the data model for the LateDeliveryAndPenalty template. | ||
* This defines the structure of the abstract syntax tree that the parser for the template | ||
* must generate from input source text. | ||
*/ | ||
@AccordTemplateModel("latedeliveryandpenalty") | ||
concept TemplateModel { | ||
/** | ||
* Does the clause include a force majeure provision? | ||
*/ | ||
o Boolean forceMajeure | ||
|
||
/** | ||
* For every penaltyDuration that the goods are late | ||
*/ | ||
o Duration penaltyDuration | ||
|
||
/** | ||
* Seller pays the buyer penaltyPercentage % of the value of the goods | ||
*/ | ||
o Double penaltyPercentage | ||
|
||
/** | ||
* Up to capPercentage % of the value of the goods | ||
*/ | ||
o Double capPercentage | ||
|
||
/** | ||
* If the goods are >= termination late then the buyer may terminate the contract | ||
*/ | ||
o Duration termination | ||
|
||
/** | ||
* Fractional part of a ... is considered a whole ... | ||
*/ | ||
o TemporalUnit fractionalPart | ||
} | ||
|
||
/** | ||
* Defines the input data required by the template | ||
*/ | ||
transaction LateDeliveryAndPenaltyRequest { | ||
|
||
/** | ||
* Are we in a force majeure situation? | ||
*/ | ||
o Boolean forceMajeure | ||
|
||
/** | ||
* What was the agreed delivery date for the goods? | ||
*/ | ||
o DateTime agreedDelivery | ||
|
||
/** | ||
* If the goods have been delivered, when where they delivered? | ||
*/ | ||
o DateTime deliveredAt optional | ||
|
||
/** | ||
* What is the value of the goods? | ||
*/ | ||
o Double goodsValue | ||
} | ||
|
||
/** | ||
* Defines the output data for the template | ||
*/ | ||
transaction LateDeliveryAndPenaltyResponse { | ||
/** | ||
* The penalty to be paid by the seller | ||
*/ | ||
o Double penalty | ||
|
||
/** | ||
* Whether the buyer may terminate the contract | ||
*/ | ||
o Boolean buyerMayTerminate | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$class": "org.accordproject.latedeliveryandpenalty.LateDeliveryAndPenaltyRequest", | ||
"forceMajeure": false, | ||
"agreedDelivery": "2019-01-31 03:24:00Z", | ||
"deliveredAt": null, | ||
"goodsValue": 200.00 | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/latedeliveryandpenaltyelse/request-forcemajeure.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$class": "org.accordproject.latedeliveryandpenalty.LateDeliveryAndPenaltyRequest", | ||
"forceMajeure": true, | ||
"agreedDelivery": "2018-01-31 03:24:00Z", | ||
"deliveredAt": null, | ||
"goodsValue": 200.00 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$class": "org.accordproject.latedeliveryandpenalty.LateDeliveryAndPenaltyRequest", | ||
"forceMajeure": false, | ||
"agreedDelivery": "2018-01-31 03:24:00Z", | ||
"deliveredAt": null, | ||
"goodsValue": 200.00 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ "$class": "org.accordproject.cicero.contract.AccordContractState", | ||
"stateId" : "1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Late Delivery and Penalty. In case of delayed delivery{{#if forceMajeure}} except for Force Majeure cases,{{else}} even in cases of Force Majeure,{{/if}} the Seller shall pay to the Buyer for every {{penaltyDuration}} of delay penalty amounting to {{penaltyPercentage}}% of the total value of the Equipment whose delivery has been delayed. Any fractional part of a {{fractionalPart}} is to be considered a full {{fractionalPart}}. The total amount of penalty shall not however, exceed {{capPercentage}}% of the total value of the Equipment involved in late delivery. If the delay is more than {{termination}}, the Buyer is entitled to terminate this Contract. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.